1、新建一个窗体,创建一个文本框和命令按钮,加入下面代码: Option Explicit Private Sub Command1_Click() Dim c1 As New Class1 MsgBox c1.DigestStrToHexStr(Text1.Text) End Sub 2、添加一个类模块,加入下面代码: Option Explicit Private Const OFFSET_4 = 4294967296# Private Const MAXINT_4 = 2147483647 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 Dim a As Byte Dim b As Byte Dim c As Byte Dim d As Byte
VB6.0实现DB5加密
最新推荐文章于 2022-06-03 14:15:59 发布