![]() |
#2
mrye2013-03-22 00:27
|



不知道有没有大手可以帮下忙指点下或者解释下。代码如下:

Private Sub Command1_Click()
Dim aH
aH = Hash(CStr(Text1.Text))
Debug.Print aH
End Sub
Public Function Hash(ET As String) As String
Dim BitLenString As String, KeyString As String, FileText As String
BitLenString = "12345678"
KeyString = ET & BitLenString
Call Initialize(KeyString)
'根据KeyString产生随机数序列
FileText = ET & BitLenString
Call DoXor(FileText)
'根据上述随机数序列对FileText加密
KeyString = FileText
Call Initialize(KeyString)
'根据上述的加密结果产生新的随机数序列
FileText = BitLenString
Call DoXor(FileText)
'根据上述随机数序列对FileText加密,8位字符
Hash = FileText
'8位字符送作HASH值
End Function
Public Sub DoXor(ByRef msFileText As String)
Dim intC As Integer
Dim intB As Integer
Dim lngI As Long
'下面,用Rnd产生随机序列数,然后根据Int(Rnd * 2 ^ 7)得到一个对应整数,
'再用该整数与msFileText中字符XOR.
For lngI = 1 To Len(msFileText)
intC = AscW(Mid(msFileText, lngI, 1))
intB = Int(Rnd * 2 ^ 7)
'选用< =127可正确处理汉字,ChrW(n):n 有一个范围
Mid(msFileText, lngI, 1) = ChrW(intC Xor intB)
Next lngI
End Sub
Private Sub Initialize(vKeyString As String)
Dim intI As Integer, intJ As Integer
Randomize Rnd(-1) '得到初始值(种子值)
'每次调用初始值均相同
'根据初始值(种子值)得到随机数序列,每次调用Initialize时,初始值均相同。只要vKeyString相同,所产生的随机数序列一定相同
For intI = 1 To Len(vKeyString)
intJ = Rnd(-Rnd * AscW(Mid(vKeyString, intI, 1)))
Randomize intJ
Next intI
End Sub
Dim aH
aH = Hash(CStr(Text1.Text))
Debug.Print aH
End Sub
Public Function Hash(ET As String) As String
Dim BitLenString As String, KeyString As String, FileText As String
BitLenString = "12345678"
KeyString = ET & BitLenString
Call Initialize(KeyString)
'根据KeyString产生随机数序列
FileText = ET & BitLenString
Call DoXor(FileText)
'根据上述随机数序列对FileText加密
KeyString = FileText
Call Initialize(KeyString)
'根据上述的加密结果产生新的随机数序列
FileText = BitLenString
Call DoXor(FileText)
'根据上述随机数序列对FileText加密,8位字符
Hash = FileText
'8位字符送作HASH值
End Function
Public Sub DoXor(ByRef msFileText As String)
Dim intC As Integer
Dim intB As Integer
Dim lngI As Long
'下面,用Rnd产生随机序列数,然后根据Int(Rnd * 2 ^ 7)得到一个对应整数,
'再用该整数与msFileText中字符XOR.
For lngI = 1 To Len(msFileText)
intC = AscW(Mid(msFileText, lngI, 1))
intB = Int(Rnd * 2 ^ 7)
'选用< =127可正确处理汉字,ChrW(n):n 有一个范围
Mid(msFileText, lngI, 1) = ChrW(intC Xor intB)
Next lngI
End Sub
Private Sub Initialize(vKeyString As String)
Dim intI As Integer, intJ As Integer
Randomize Rnd(-1) '得到初始值(种子值)
'每次调用初始值均相同
'根据初始值(种子值)得到随机数序列,每次调用Initialize时,初始值均相同。只要vKeyString相同,所产生的随机数序列一定相同
For intI = 1 To Len(vKeyString)
intJ = Rnd(-Rnd * AscW(Mid(vKeyString, intI, 1)))
Randomize intJ
Next intI
End Sub