ASP加密解密函數(shù)
當(dāng)前位置:點(diǎn)晴教程→知識管理交流
→『 技術(shù)文檔交流 』
[code]
<%
key="sdfjal;dfjaoiejojfafnsanf;aufweijoanfanfaieufowejrwnf;aupagyuweranfsajfagfuoag" '私鑰
sub rc4initialize(strpwd,byref sbox,byref key)
dim tempswap
dim a
dim b
intlength = len(strpwd)
for a = 0 to 255
key(a) = asc(mid(strpwd, (a mod intlength)+1, 1))
sbox(a) = a
next
b = 0
for a = 0 to 255
b = (b + sbox(a) + key(a)) mod 256
tempswap = sbox(a)
sbox(a) = sbox(b)
sbox(b) = tempswap
next
end sub
function encrypt(plaintxt, psw)
dim sbox(255)
dim key(255)
dim temp
dim a
dim i
dim j
dim k
dim cipherby
dim cipher
i = 0
j = 0
rc4initialize psw,sbox,key
for a = 1 to len(plaintxt)
i = (i + 1) mod 256
j = (j + sbox(i)) mod 256
temp = sbox(i)
sbox(i) = sbox(j)
sbox(j) = temp
k = sbox((sbox(i) + (sbox(j) mod 256)) mod 256)
cipherby = asc(mid(plaintxt, a, 1)) xor k
cipher = cipher & ""&cipherby&";" 'eg: €
next
encrypt = cipher
end function
function decrypt(cryptxt, psw)
dim sbox(255)
dim key(255)
dim temp
dim a
dim i
dim j
dim k
dim cipherby
dim cipher
i = 0
j = 0
rc4initialize psw,sbox,key
crypchar=split(cryptxt,";",-1,1) '將密文拆分成每個密文字符放入數(shù)組crypchar,但是每個數(shù)組元素少一個分號“;”
crypttxtlen=ubound(crypchar) '返回數(shù)組的個數(shù),即加密字符的個數(shù)+1(數(shù)組中最后一個元素為空)
for a = 1 to crypttxtlen
i = (i + 1) mod 256
j = (j + sbox(i)) mod 256
temp = sbox(i)
sbox(i) = sbox(j)
sbox(j) = temp
k = sbox((sbox(i) + (sbox(j) mod 256)) mod 256)
tmpcryptxt=mid(crypchar(i-1),3)
cipherby = tmpcryptxt xor k
cipher = cipher & ""&cipherby&";" 'eg: €
next
decrypt = cipher
end function
if request.servervariables("request_method") = "post" then
plaintext=request.form("plaintext")
response.write "
輸入的明文字符串是:"&plaintext cryptext=encrypt(plaintext,key) response.write " 加密后的密文字符串:" &cryptext decryptext=decrypt(cryptext,key) response.write " 解密輸出的字符串是:" &decryptext end if %> 該文章在 2010/5/8 15:57:36 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |