|
MD5加密算法:
Option Explicit
Dim w1 As String, w2 As String, w3 As String, w4 As String
Function MD5F(ByVal tempstr As String, ByVal w As String, ByVal X As S
tring, ByVal y As String, ByVal z As String, ByVal Xin As String, ByVa
l qdata As String, ByVal rots As Integer)
MD5F = BigMod32Add(RotLeft(BigMod32Add(BigMod32Add(w, tempstr), Bi
gMod32Add(Xin, qdata)), rots), X)
End Function
Sub MD5F1(w As String, ByVal X As String, ByVal y As String, ByVal z A
s String, ByVal Xin As String, ByVal qdata As String, ByVal rots As In
teger)
Dim tempstr As String
tempstr = BigXOR(z, BigAND(X, BigXOR(y, z)))
w = MD5F(tempstr, w, X, y, z, Xin, qdata, rots)
End Sub
Sub MD5F2(w As String, ByVal X As String, ByVal y As String, ByVal z A
s String, ByVal Xin As String, ByVal qdata As String, ByVal rots As In
teger)
Dim tempstr As String
tempstr = BigXOR(y, BigAND(z, BigXOR(X, y)))
w = MD5F(tempstr, w, X, y, z, Xin, qdata, rots)
End Sub
Sub MD5F3(w As String, ByVal X As String, ByVal y As String, ByVal z A
s String, ByVal Xin As String, ByVal qdata As String, ByVal rots As In
teger)
Dim tempstr As String
tempstr = BigXOR(X, BigXOR(y, z))
w = MD5F(tempstr, w, X, y, z, Xin, qdata, rots)
End Sub
Sub MD5F4(w As String, ByVal X As String, ByVal y As String, ByVal z A
s String, ByVal Xin As String, ByVal qdata As String, ByVal rots As In
teger)
Dim tempstr As String
tempstr = BigXOR(y, BigOR(X, BigNOT(z)))
w = MD5F(tempstr, w, X, y, z, Xin, qdata, rots)
End Sub
Function MD5_Calc(ByVal hashthis As String) As String
ReDim buf(0 To 3) As String
ReDim Xin(0 To 15) As String
Dim tempnum As Integer, tempnum2 As Integer, loopit As Integer, loopou
ter As Integer, loopinner As Integer
Dim a As String, b As String, c As String, d As String
' Add padding
tempnum = 8 * Len(hashthis)
hashthis = hashthis + Chr$(128) 'Add binary 10000000
tempnum2 = 56 - Len(hashthis) Mod 64
If tempnum2 < 0 Then
tempnum2 = 64 + tempnum2
End If
hashthis = hashthis + String$(tempnum2, Chr$(0))
For loopit = 1 To 8
hashthis = hashthis + Chr$(tempnum Mod 256)
tempnum = tempnum - tempnum Mod 256
tempnum = tempnum / 256
Next loopit
' Set magic numbers
buf(0) = "67452301"
buf(1) = "efcdab89"
buf(2) = "98badcfe"
buf(3) = "10325476"
' For each 512 bit section
For loopouter = 0 To Len(hashthis) / 64 - 1
a = buf(0)
b = buf(1)
c = buf(2)
d = buf(3)
' Get the 512 bits
For loopit = 0 To 15
Xin(loopit) = ""
For loopinner = 1 To 4
Xin(loopit) = Hex$(Asc(Mid$(hashthis, 64 * loopouter +
4 * loopit + loopinner, 1))) + Xin(loopit)
If Len(Xin(loopit)) Mod 2 Then Xin(loopit) = "0" + Xin
(loopit)
Next loopinner
Next loopit
' Round 1
MD5F1 a, b, c, d, Xin(0), "d76aa478", 7
MD5F1 d, a, b, c, Xin(1), "e8c7b756", 12
MD5F1 c, d, a, b, Xin(2), "242070db", 17
MD5F1 b, c, d, a, Xin(3), "c1bdceee", 22
MD5F1 a, b, c, d, Xin(4), "f57c0faf", 7
MD5F1 d, a, b, c, Xin(5), "4787c62a", 12
MD5F1 c, d, a, b, Xin(6), "a8304613", 17
MD5F1 b, c, d, a, Xin(7), "fd469501", 22
MD5F1 a, b, c, d, Xin(8), "698098d8", 7
MD5F1 d, a, b, c, Xin(9), "8b44f7af", 12
MD5F1 c, d, a, b, Xin(10), "ffff5bb1", 17
MD5F1 b, c, d, a, Xin(11), "895cd7be", 22
MD5F1 a, b, c, d, Xin(12), "6b901122", 7
MD5F1 d, a, b, c, Xin(13), "fd987193", 12
MD5F1 c, d, a, b, Xin(14), "a679438e", 17
MD5F1 b, c, |
|