<%
最簡單的加密方法:XOR
----------------------
g_CryptThis = "中國-China"
strFullKeyLen = Len(g_CryptThis)
strFullKey = KeyGen(strFullKeyLen)
Response.Write "<p>原始字串: " & g_CryptThis & "<p>"
Response.Write "<p>密鑰: " & strFullKey & "<p>"
Response.Write "<p>加密後: " & Server.URLEncode(EnCrypt(g_CryptThis)) & "<p>"
Response.Write "<p>解密後: " & DeCrypt(EnCrypt(g_CryptThis)) & "<p>"
異或加密
Function EnCrypt(strCryptThis)
Dim strChar, iKeyChar, iStringChar, i
for i = 1 to Len(strCryptThis)
iKeyChar = Asc(mid(strFullKey,i,1))
iStringChar = Asc(mid(strCryptThis,i,1))
iCryptChar = iKeyChar Xor iStringChar
strEncrypted = strEncrypted & Chr(iCryptChar)
next
EnCrypt = strEncrypted
End Function
異或解密
Function DeCrypt(strEncrypted)
Dim strChar, iKeyChar, iStringChar, i
for i = 1 to Len(strEncrypted)
iKeyChar = (Asc(mid(strFullKey,i,1)))
iStringChar = Asc(mid(strEncrypted,i,1))
iDeCryptChar = iKeyChar Xor iStringChar
strDecrypted = strDecrypted & Chr(iDeCryptChar)
next
DeCrypt = strDecrypted
End Function
產生指定長度的隨機密鑰
Function KeyGen(strlength)
Dim i,UB
Dim Temp
Dim Poss
Poss = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
Temp = ""
UB = Len(Poss)
For i = 1 To strlength
Randomize
Temp = Temp & Mid(Poss,Int((UB - 0 + 1) * Rnd + 1),1)
Next
KeyGen = Temp
End Function
%>