'= Name: modPassword
'= Description: This function for string encrypt
'= Author: Super.Wang
'= Date: 2004/11/01
'================================================
'= Please Do Not Remove These Comment Lines!
Public Function sumPassword(ByVal strSource As String) As String
If Len(strSource) = 0 Then Exit Function
Dim buff() As Byte
buff = StrConv(strSource, vbFromUnicode)
Dim i As Long
Dim j As Byte
Dim k As Byte, m As Byte
Dim mstr As String
mstr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"
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) '最大产生的随机数只能是5,不能再大了,再大的话,就要多用一个字节
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
'将密码字符串反转
Dim intTemp, intFor As Integer
Dim strTemp, strOut As String
intTemp = Len(outs)
For intFor = 0 To intTemp - 1
strTemp = Mid(outs, intTemp - intFor, 1)
strOut = strOut + strTemp
Next
sumPassword = strOut
End Function
'还原密码,Super 04/11/1 改。
Public Function returnPassword(strPassword As String) As String
On Error GoTo err
'将密码字符串反转
Dim intTemp, intFor As Integer
Dim strTemp, strOut As String
intTemp = Len(strPassword)
For intFor = 0 To intTemp - 1
strTemp = Mid(strPassword, intTemp - intFor, 1)
strOut = strOut + strTemp
Next
strPassword = strOut
'解密开始
Dim i As Long
Dim j As Byte
Dim k As Byte
Dim m As Byte
Dim mstr As String
mstr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"
Dim t1 As String, t2 As String
Dim buff() As Byte
Dim n As Long
n = 0
For i = 1 To Len(strPassword) Step 2
t1 = Mid(strPassword, i, 1)
t2 = Mid(strPassword, i + 1, 1)
k = InStr(1, mstr, t1) - 1
m = InStr(1, mstr, t2) - 1
j = m / 2 ^ 3
m = m - j * 2 ^ 3
ReDim Preserve buff(n)
buff(n) = j * Len(mstr) + k
buff(n) = buff(n) Xor m
n = n + 1
Next
returnPassword = StrConv(buff, vbUnicode)
Exit Function
err:
returnPassword = ""
End Function
'= Description: This function for string encrypt
'= Author: Super.Wang
'= Date: 2004/11/01
'================================================
'= Please Do Not Remove These Comment Lines!
Public Function sumPassword(ByVal strSource As String) As String
If Len(strSource) = 0 Then Exit Function
Dim buff() As Byte
buff = StrConv(strSource, vbFromUnicode)
Dim i As Long
Dim j As Byte
Dim k As Byte, m As Byte
Dim mstr As String
mstr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"
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) '最大产生的随机数只能是5,不能再大了,再大的话,就要多用一个字节
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
'将密码字符串反转
Dim intTemp, intFor As Integer
Dim strTemp, strOut As String
intTemp = Len(outs)
For intFor = 0 To intTemp - 1
strTemp = Mid(outs, intTemp - intFor, 1)
strOut = strOut + strTemp
Next
sumPassword = strOut
End Function
'还原密码,Super 04/11/1 改。
Public Function returnPassword(strPassword As String) As String
On Error GoTo err
'将密码字符串反转
Dim intTemp, intFor As Integer
Dim strTemp, strOut As String
intTemp = Len(strPassword)
For intFor = 0 To intTemp - 1
strTemp = Mid(strPassword, intTemp - intFor, 1)
strOut = strOut + strTemp
Next
strPassword = strOut
'解密开始
Dim i As Long
Dim j As Byte
Dim k As Byte
Dim m As Byte
Dim mstr As String
mstr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"
Dim t1 As String, t2 As String
Dim buff() As Byte
Dim n As Long
n = 0
For i = 1 To Len(strPassword) Step 2
t1 = Mid(strPassword, i, 1)
t2 = Mid(strPassword, i + 1, 1)
k = InStr(1, mstr, t1) - 1
m = InStr(1, mstr, t2) - 1
j = m / 2 ^ 3
m = m - j * 2 ^ 3
ReDim Preserve buff(n)
buff(n) = j * Len(mstr) + k
buff(n) = buff(n) Xor m
n = n + 1
Next
returnPassword = StrConv(buff, vbUnicode)
Exit Function
err:
returnPassword = ""
End Function