647
Private Const S11 = 7
Private Const S12 = 12
Private Const S13 = 17
Private Const S14 = 22
Private Const S21 = 5
Private Const S22 = 9
Private Const S23 = 14
Private Const S24 = 20
Private Const S31 = 4
Private Const S32 = 11
Private Const S33 = 16
Private Const S34 = 23
Private Const S41 = 6
Private Const S42 = 10
Private Const S43 = 15
Private Const S44 = 21
''=
''= Class Variables
''=
Private State(4) As Long
Private ByteCounter As Long
Private ByteBuffer(63) As Byte
''=
''= Class Properties
''=
Property Get RegisterA() As String
RegisterA = State(1)
End Property
Property Get RegisterB() As String
RegisterB = State(2)
End Property
Property Get RegisterC() As String
RegisterC = State(3)
End Property
Property Get RegisterD() As String
RegisterD = State(4)
End Property
''=
''= Class Functions
''=
''
'' Function to quickly digest a file into a hex string
''
Public Function DigestFileToHexStr(FileName As String) As String
Open FileName For Binary Access Read As #1
MD5Init
Do While Not EOF(1)
Get #1, , ByteBuffer
If Loc(1) < LOF(1) Then
ByteCounter = ByteCounter + 64
MD5Transform ByteBuffer
End If
Loop
ByteCounter = ByteCounter + (LOF(1) Mod 64)
Close #1
MD5Final
DigestFileToHexStr = GetValues
End Function
''
'' Function to digest a text string and output the result as a string
'' of hexadecimal characters.
''
Public Function DigestStrToHexStr(SourceString As String) As String
MD5Init
MD5Update Len(SourceString), StringToArray(SourceString)
MD5Final
DigestStrToHexStr = GetValues
End Function
''
'' A utility function which converts a string into an array of
'' bytes.
''
Private Function StringToArray(InString As String) As Byte()
Dim I As Integer
Dim bytBuffer() As Byte
ReDim bytBuffer(Len(InString))
For I = 0 To Len(InString) - 1
bytBuffer(I) = Asc(Mid(InString, I + 1, 1))
Next I
StringToArray = bytBuffer
End Function
''
'' Concatenate the four state vaules into one string
''
Public Function GetValues() As String
GetValues = LongToString(State(1)) & LongToString(State(2)) & LongToString(State(3)) & LongToString(State(4))
End Function
''
'' Convert a Long to a Hex string
''
Private Function LongToString(Num As Long) As String
&