一个简单的加密/解密方法

2016-01-29 13:47 18 1 收藏

一个简单的加密/解密方法,一个简单的加密/解密方法

【 tulaoshi.com - ASP.NET 】

Private Function EncryptString(strString)
Dim CharHexSet, intStringLen, strTemp, strRAW, i, intKey, intOffSet
Randomize Timer

intKey = Round((RND * 1000000) + 1000000) '##### Key Bitsize
intOffSet = Round((RND * 1000000) + 1000000) '##### KeyOffSet Bitsize

If IsNull(strString) = False Then
strRAW = strString
intStringLen = Len(strRAW)

For i = 0 to intStringLen - 1
strTemp = Left(strRAW, 1)
strRAW = Right(strRAW, Len(strRAW) - 1)
CharHexSet = CharHexSet & Hex(Asc(strTemp) * intKey)& Hex(intKey)
Next

EncryptString = CharHexSet & "|" & Hex(intOffSet + intKey) & "|" & Hex(intOffSet)
Else
EncryptString = ""
End If
End Function

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com)

Private Function DecryptString(strCryptString)
Dim strRAW, arHexCharSet, i, intKey, intOffSet, strRawKey, strHexCrypData

strRawKey = Right(strCryptString, Len(strCryptString) - InStr(strCryptString, "|"))
intOffSet = Right(strRawKey, Len(strRawKey) - InStr(strRawKey,"|"))
intKey = HexConv(Left(strRawKey, InStr(strRawKey, "|") - 1)) - HexConv(intOffSet)
strHexCrypData = Left(strCryptString, Len(strCryptString) - (Len(strRawKey) + 1))

arHexCharSet = Split(strHexCrypData, Hex(intKey))

For i=0 to UBound(arHexCharSet)
strRAW = strRAW & Chr(HexConv(arHexCharSet(i))/intKey)
Next

DecryptString = strRAW
End Function

Private Function HexConv(hexVar)
Dim hxx, hxx_var, multiply
IF hexVar < "" THEN
hexVar = UCASE(hexVar)
hexVar = StrReverse(hexVar)
DIM hx()
REDIM hx(LEN(hexVar))
hxx = 0
hxx_var = 0
FOR hxx = 1 TO LEN(hexVar)
IF multiply = "" THEN multiply = 1
hx(hxx) = mid(hexVar,hxx,1)
hxx_var = (get_hxno(hx(hxx)) * multiply) + hxx_var
multiply = (multiply * 16)
NEXT
hexVar = hxx_var
HexConv = hexVar
END IF
End Function

Private Function get_hxno(ghx)
If ghx = "A" Then
ghx = 10
ElseIf ghx = "B" Then
ghx = 11
ElseIf ghx = "C" Then
ghx = 12
ElseIf ghx = "D" Then
ghx = 13
ElseIf ghx = "E" Then
ghx = 14
ElseIf ghx = "F" Then
ghx = 15
End If
get_hxno = ghx
End Function


 

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com)

来源:http://www.tulaoshi.com/n/20160129/1491517.html

延伸阅读
#include graphics.h #include stdio.h #include math.h #include time.h #define PI 3.14159 #define maxx 640 #define maxy 480main() {int i;  char c;  init();  draw();  c=getch(); } init() /*初始化图形系统函数*/ {int gdriver=DETECT,gmode; &n...
  unit Unit1; interface uses   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,   Dialogs, jpeg, ExtCtrls, StdCtrls, ComCtrls, Grids,   DirOutln, Buttons, DdeMan,shlobj,comobj,activex; type   TForm1 = class(TForm)   &nbs...
//使用客户端的公共密钥加密对称密钥并发送给客。encryptAndSendSymmetricKey(client, rsa, symm);//使用对称密钥加密信息并发送encryptAndSendSecretMessage(client, symm, msg);}catch (Exception e){Console.WriteLine(e.Message);Console.WriteLine(e.StackTrace);}finally{try{client.Close();listener.Stop();}catch{//错误}Console.Writ...
使用私有密钥解密该文档,这是唯一可以解密的密钥,并且没有通过网络传递。 不对称算法比对称算法计算的花费多、速度慢。因此我们不希望在线对话中使用不对称算法加密所有信息。相反,我们使用对称算法。下面的例子中我们使用不对称加密来加密对称密钥。接着就使用对称算法加密了。实际上安全接口层(SSL)建立服务器和浏览器之间的安全对话...
                                一个简单的一箭穿心程序    其实这个程序也不难,只要专心形线方程(1-ρ×cosθ)来绘图就可以了。    作者:...

经验教程

210

收藏

24
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部