明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

容易的加密方法:XOR

[摘要]念書的時(shí)候使用對(duì)數(shù)據(jù)進(jìn)行加密的方法最簡(jiǎn)單的就是異或了,看到有人想要加密算法,就把以前的資料翻了一下,整理了一系列加密的函數(shù),當(dāng)然簡(jiǎn)單的加密也是容易破解的,但聊勝于無(記得把密要鑰放好了),總比讓人一打開數(shù)據(jù)庫就看見密碼明碼好吧。:-)<%'最簡(jiǎn)單的加密方法:XOR'-----...
念書的時(shí)候使用對(duì)數(shù)據(jù)進(jìn)行加密的方法最簡(jiǎn)單的就是異或了,看到有人想要加密算法,就把以前的資料翻了一下,整理了一系列加密的函數(shù),當(dāng)然簡(jiǎn)單的加密也是容易破解的,但聊勝于無(記得把密要鑰放好了),總比讓人一打開數(shù)據(jù)庫就看見密碼明碼好吧。:-)

<%
'最簡(jiǎn)單的加密方法: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

'產(chǎn)生指定長度的隨機(jī)密鑰
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
%>




標(biāo)簽:容易的加密辦法:XOR