'代码出处:http://www.jb51.net/article/10470.htm
'注意事项:字符串中不能有空格
Dim A_Key
Private Sub Form_Load()
A_Key = Split("68,44,38,91", ",") '自定义密钥
End Sub
'*********加密的过程*********
Function EnCrypt(m)
Dim strChar
Dim iKeyChar
Dim iStringChar
Dim I
k = 0
For I = 1 To Len(m)
iKeyChar = CInt(A_Key(k))
iStringChar = Asc(Mid(m, I, 1)) '获取字符的ASCII码值
iCryptChar = iKeyChar Xor iStringChar '进行异或运算
'对密钥进行移位运算
If k < 3 Then
k = k + 1
Else
k = 0
End If
c = c & Chr(iCryptChar)
Next
EnCrypt = c
End Function
'*********解密的过程*********
Function DeCrypt(c)
Dim strChar
Dim iKeyChar
Dim iStringChar
Dim I
k = 0
For I = 1 To Len(c)
iKeyChar = CInt(A_Key(k))
iStringChar = Asc(Mid(c, I, 1))
iDeCryptChar = iKeyChar Xor iStringChar '进行异或运算
'对密钥进行移位运算
If k < 3 Then
k = k + 1
Else
k = 0
End If
strDecrypted = strDecrypted & Chr(iDeCryptChar)
Next
DeCrypt = strDecrypted
End Function
Private Sub Command1_Click()
Text1.Text = EnCrypt(Text1.Text)
End Sub
Private Sub Command2_Click()
Text1.Text = DeCrypt(Text1.Text)
End Sub