Option Explicit
Private Const strEncryption As String = "Wa7kao19Oh54My256God!"
'XOR加密/解密函数
Public Function XOREncryption(strDataIn As String, Optional ByVal strCodeKey As String = "") As String
Dim lonDataPtr As Long
Dim intXORValue1 As Integer
Dim intXORValue2 As Integer
Dim strDataOut As String
If Len(strCodeKey) < 2 Then
strCodeKey = strEncryption
End If
Mid(strCodeKey, 2, 1) = Asc(Chr(1))
For lonDataPtr = 1 To Len(strDataIn)
'第一个XOR的值来自加密字符串
intXORValue1 = Asc(Mid$(strDataIn, lonDataPtr, 1))
'第二个XOR的值来自需要加密的数据(字符串)
intXORValue2 = Asc(Mid$(strCodeKey, ((lonDataPtr Mod Len(strCodeKey)) + 1), 1))
'两个值被XOR后成为一个需要被解密的字符
strDataOut = strDataOut + Chr(intXORValue1 Xor intXORValue2)
Next lonDataPtr
'返回被加密/解密后的数据(是一个字符串)
XOREncryption = strDataOut
End Function
评论