VB6 加密与解密
最近在学习加密与解密,突然在网上看到这几段代码,我把text1的值代入到Hash函数中运行得到aH值,但是我不知道该怎样把aH的值还原为text1原来的值。不知道有没有大手可以帮下忙指点下或者解释下。代码如下:
程序代码:
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