3 个解决方案
#2
弄了几天,实在没辙了,那个流对象不实在会修改,改了总是提示类型不匹配
Public Function Encode(ByVal S As String, ByVal key As String) As String '加密
On Error GoTo err
If Len(S) = 0 Then Exit Function
Dim Buff() As Byte
Buff = StrConv(S, vbFromUnicode)
Dim i As Long
Dim j As Byte
Dim k As Byte, m As Byte
Dim mstr As String
mstr = key
Dim outs As String
i = UBound(Buff) + 1
outs = Space(2 * i)
Dim Temps As String
For i = 0 To UBound(Buff)
Randomize Time
j = CByte(5 * (Math.Rnd()) + 0) '
Buff(i) = Buff(i) Xor j
k = Buff(i) Mod Len(mstr)
m = Buff(i) \ Len(mstr)
m = m * 2 ^ 3 + j
Temps = Mid(mstr, k + 1, 1) + Mid(mstr, m + 1, 1)
Mid(outs, 2 * i + 1, 2) = Temps
Next
Encode = outs
Exit Function
err:
End Function
这是我们论坛某位达人的加解密代码,为什么加入“Randomize Time”之后,加密的结果都不同了呢?而且还能还原回来?
Public Function Encode(ByVal S As String, ByVal key As String) As String '加密
On Error GoTo err
If Len(S) = 0 Then Exit Function
Dim Buff() As Byte
Buff = StrConv(S, vbFromUnicode)
Dim i As Long
Dim j As Byte
Dim k As Byte, m As Byte
Dim mstr As String
mstr = key
Dim outs As String
i = UBound(Buff) + 1
outs = Space(2 * i)
Dim Temps As String
For i = 0 To UBound(Buff)
Randomize Time
j = CByte(5 * (Math.Rnd()) + 0) '
Buff(i) = Buff(i) Xor j
k = Buff(i) Mod Len(mstr)
m = Buff(i) \ Len(mstr)
m = m * 2 ^ 3 + j
Temps = Mid(mstr, k + 1, 1) + Mid(mstr, m + 1, 1)
Mid(outs, 2 * i + 1, 2) = Temps
Next
Encode = outs
Exit Function
err:
End Function
这是我们论坛某位达人的加解密代码,为什么加入“Randomize Time”之后,加密的结果都不同了呢?而且还能还原回来?
#3
Buff = StrConv(S, vbFromUnicode)在这里似乎只起到分成数组的作用,我用一个函数返回数组也行得通,就是不知道会出什么问题
#1
#2
弄了几天,实在没辙了,那个流对象不实在会修改,改了总是提示类型不匹配
Public Function Encode(ByVal S As String, ByVal key As String) As String '加密
On Error GoTo err
If Len(S) = 0 Then Exit Function
Dim Buff() As Byte
Buff = StrConv(S, vbFromUnicode)
Dim i As Long
Dim j As Byte
Dim k As Byte, m As Byte
Dim mstr As String
mstr = key
Dim outs As String
i = UBound(Buff) + 1
outs = Space(2 * i)
Dim Temps As String
For i = 0 To UBound(Buff)
Randomize Time
j = CByte(5 * (Math.Rnd()) + 0) '
Buff(i) = Buff(i) Xor j
k = Buff(i) Mod Len(mstr)
m = Buff(i) \ Len(mstr)
m = m * 2 ^ 3 + j
Temps = Mid(mstr, k + 1, 1) + Mid(mstr, m + 1, 1)
Mid(outs, 2 * i + 1, 2) = Temps
Next
Encode = outs
Exit Function
err:
End Function
这是我们论坛某位达人的加解密代码,为什么加入“Randomize Time”之后,加密的结果都不同了呢?而且还能还原回来?
Public Function Encode(ByVal S As String, ByVal key As String) As String '加密
On Error GoTo err
If Len(S) = 0 Then Exit Function
Dim Buff() As Byte
Buff = StrConv(S, vbFromUnicode)
Dim i As Long
Dim j As Byte
Dim k As Byte, m As Byte
Dim mstr As String
mstr = key
Dim outs As String
i = UBound(Buff) + 1
outs = Space(2 * i)
Dim Temps As String
For i = 0 To UBound(Buff)
Randomize Time
j = CByte(5 * (Math.Rnd()) + 0) '
Buff(i) = Buff(i) Xor j
k = Buff(i) Mod Len(mstr)
m = Buff(i) \ Len(mstr)
m = m * 2 ^ 3 + j
Temps = Mid(mstr, k + 1, 1) + Mid(mstr, m + 1, 1)
Mid(outs, 2 * i + 1, 2) = Temps
Next
Encode = outs
Exit Function
err:
End Function
这是我们论坛某位达人的加解密代码,为什么加入“Randomize Time”之后,加密的结果都不同了呢?而且还能还原回来?
#3
Buff = StrConv(S, vbFromUnicode)在这里似乎只起到分成数组的作用,我用一个函数返回数组也行得通,就是不知道会出什么问题