//都是基于字节的加密 同意给你写了个最简单的:Option Explicit '加密 Private Function Encrypt(ByVal strSource As String, ByVal Key As Byte) As String Dim i As Long Dim j As Byte Dim temps As String Dim s As String Dim arr() As Byte arr = StrConv(strSource, vbFromUnicode) For i = 0 To UBound(arr) j = arr(i) Xor Key temps = Right("00" & Hex(j), 2) s = s + temps Next Encrypt = s End Function '解密 Private Function decrypt(ByVal strSource As String, ByVal Key As Byte) As String Dim i As Long Dim j As Long Dim temps As String Dim s As String Dim arr As Variant i = Len(strSource) If i Mod 2 = 1 Then '待解密的字串不符合要求 decrypt = "" Exit Function End If Dim buff() As Byte Dim k As Long k = 0 For i = 1 To Len(strSource) Step 2 temps = Mid(strSource, i, 2) j = Val("&H" & temps) j = j Xor Key ReDim Preserve buff(k) buff(k) = j k = k + 1 Next decrypt = StrConv(buff, vbUnicode) End FunctionPrivate Sub Command1_Click() Dim s As String s = "abc中国123456" s = Encrypt(s, 253) Debug.Print s s = decrypt(s, 253) Debug.Print s End Sub
学习ing
同意给你写了个最简单的:Option Explicit
'加密
Private Function Encrypt(ByVal strSource As String, ByVal Key As Byte) As String
Dim i As Long
Dim j As Byte
Dim temps As String
Dim s As String
Dim arr() As Byte
arr = StrConv(strSource, vbFromUnicode)
For i = 0 To UBound(arr)
j = arr(i) Xor Key
temps = Right("00" & Hex(j), 2)
s = s + temps
Next
Encrypt = s
End Function
'解密
Private Function decrypt(ByVal strSource As String, ByVal Key As Byte) As String
Dim i As Long
Dim j As Long
Dim temps As String
Dim s As String
Dim arr As Variant
i = Len(strSource)
If i Mod 2 = 1 Then
'待解密的字串不符合要求
decrypt = ""
Exit Function
End If
Dim buff() As Byte
Dim k As Long
k = 0
For i = 1 To Len(strSource) Step 2
temps = Mid(strSource, i, 2)
j = Val("&H" & temps)
j = j Xor Key
ReDim Preserve buff(k)
buff(k) = j
k = k + 1
Next
decrypt = StrConv(buff, vbUnicode)
End FunctionPrivate Sub Command1_Click()
Dim s As String
s = "abc中国123456"
s = Encrypt(s, 253)
Debug.Print s
s = decrypt(s, 253)
Debug.Print s
End Sub
[email protected]
3661512(菜鸟一只) 的代码还没有收到,收到后就给大家加分了
liyan010(我是大坏蛋) ,呵呵,校友好啊,你的邮件要给出来,代码才好发给你