如何用vb实现hash函数的各个算法
发布网友
发布时间:2022-05-16 16:51
我来回答
共1个回答
热心网友
时间:2023-11-02 10:30
Private Sub Initialize(ByVal 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
Public Sub DoXor(ByRef msFileText As String)
Dim intC As Integer
Dim intB As Integer
Dim lngI As Long
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
Public Function Hash(ByVal 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
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click