<% Private const bits_to_a_byte = 8private const bytes_to_a_word = 4Private const bits_to_a_word = 32
Private m_lOnBits (30) Private m_l2Power (30) Private Function LShift (lValue, iShiftBits) If iShiftBits = 0 Then LShift = lValue Exit Function ElseIf iShiftBits = 31 Then If lValue And 1 Then LShift = & H80000000 Else LShift = 0 End If Exit Function ElseIf Ishiftbits <0 or iShiftBits> 31 Then Err.raise 6 End IF
If (lValue And m_l2Power (31 - iShiftBits)) Then LShift = ((lValue And m_lOnBits (31 - (iShiftBits 1))) * m_l2Power (iShiftBits)) Or & H80000000 Else LShift = ((lValue And m_lOnBits (31 - iShiftBits) * m_l2power (ishiftbits)) end fnd function
Private Function RShift (lValue, iShiftBits) If iShiftBits = 0 Then RShift = lValue Exit Function ElseIf iShiftBits = 31 Then If lValue And & H80000000 Then RShift = 1 Else RShift = 0 End If Exit Function ElseIf iShiftBits <0 Or iShiftBits> 31 Then Err. Raise 6 end if rshift = (LValue and & h7ffffe) / m_l2power (iShiftBits)
IF (Lvalue and & H80000000) THEN RSHIFT = (RSHIFT OR (& H40000000 / M_L2Power (IshiftBits - 1)) End IFEND Function
Private function rotateleft (Lvalue, Ishiftbits) Rotateleft = Lshift (Lvalue, IshiftBits) or Rshift (Lvalue, (32 - IshiftBits) End Function
Private Function AddUnsigned (lX, lY) Dim lX4 Dim lY4 Dim lX8 Dim lY8 Dim lResult lX8 = lX And & H80000000 lY8 = lY And & H80000000 lX4 = lX And & H40000000 lY4 = lY And & H40000000 lResult = (lX And & H3FFFFFFF) (lY And & H3FFFFFFF ) If lX4 And lY4 Then lResult = lResult Xor & H80000000 Xor lX8 Xor lY8 ElseIf lX4 Or lY4 Then If lResult And & H40000000 Then lResult = lResult Xor & HC0000000 Xor lX8 Xor lY8 Else lResult = lResult Xor & H40000000 Xor lX8 Xor lY8 End If Else lResult = lResult XOR LX8 XOR LY8 End IF Addunsigned = Lresultend FunctionPrivate Function MD5_F (X, Y, Z) MD5_F = (x AND Y) OR ((NOT X) AND Z) End Function
Private function MD5_G (X, Y, Z) MD5_G = (x and z) OR (Y AND (not z)) end function
Private function MD5_H (X, Y, Z) MD5_H = (x xor y xor z) end function
Private function MD5_I (X, Y, Z) MD5_i = (Y xor (x or (not z))) End Function
Private SUB MD5_FF (A, B, C, D, X, S, AC) a = addunsigned (A, Addunsigned (addunsigned (MD5_F (B, C, D), X), AC)) A = Rotateleft (A, S ) A = addunsigned (a, b) end sub
Private SUB MD5_GG (A, B, C, D, X, S, AC) a = addunsigned (A, addunSigned (addunsigned (MD5_G (B, C, D), X), AC)) A = Rotateleft (A, S ) A = addunsigned (a, b) end sub
Private sub md5_hh (A, B, C, D, X, S, AC) a = addunsigned (A, addunsigned (addunsigned (MD5_H (B, D), X), AC)) A = RotateLeft (A, S ) A = addunsigned (a, b) end sub
Private Sub MD5_II (A, B, C, D, X, S, AC) a = addunsigned (A, addunsigned (addunsigned (MD5_i (B, D), X), AC)) A = RotateLeft (A, S ) a = AddUnsigned (a, b) End SubPrivate Function ConvertToWordArray (sMessage) Dim lMessageLength Dim lNumberOfWords Dim lWordArray () Dim lBytePosition Dim lByteCount Dim lWordCount Const MODULUS_BITS = 512 Const CONGRUENT_BITS = 448 lMessageLength = Len (sMessage) lNumberOfWords = (((lMessageLength ((MODULUS_BITS - CONGRUENT_BITS) / BITS_TO_A_BYTE)) / (MODULUS_BITS / BITS_TO_A_BYTE)) 1) * (MODULUS_BITS / BITS_TO_A_WORD) ReDim lWordArray (lNumberOfWords - 1) lBytePosition = 0 lByteCount = 0 Do Until lByteCount> = lMessageLength lWordCount = lByteCount / BYTES_TO_A_WORD lBytePosition = lByteCount (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE lWordArray (lWordCount) = lWordArray (lWordCount) Or LShift (Asc (Mid (sMessage, lByteCount 1, 1)), lBytePosition) lByteCount = 1 LOOP
LWORDCOUNT = lbytecount / bytes_to_a_word lbyteposition = (lbytecount mode_to_a_word) * bits_to_a_byte
LWordArray (lwordcount) = lwordArray (lwordcount) or lshift (& H80, lbyteposition)
LWordArray (lnumberofwords - 2) = lshift (LMESSAGALELENGTH, 3) LWORDARRAY (Lnumberofwords - 1) = Rshift (LMessageLength, 29) ConvertToWordArray = LWORDARRAYEND FUNCTION
Private Function WordToHex (lValue) Dim lByte Dim lCount For lCount = 0 To 3 lByte = RShift (lValue, lCount * BITS_TO_A_BYTE) And m_lOnBits (BITS_TO_A_BYTE - 1) WordToHex = WordToHex & Right ( "0" & Hex (lByte), 2) NEXTEND FUNCTION
Public Function MD5 (SMESSAGE) M_LONBITS (0) = clng (1) m_lonbits (1) = ClNG (3) M_Lonbits (2) = ClNG (7) M_LONBITS (3) = CLNG (15) M_LONBITS (4) = CLNG (31 ) M_lonbits (5) = clng (63) M_LONBITS (6) = clng (127) m_lonbits (7) = clng (255) m_lonbits (8) = CLNG (511) m_lonbits (9) = CLNG (1023) m_lonbits (10) = ClNG (2047) m_lonbits (11) = clng (4095) m_lonbits (12) = clng (8191) m_lonbits (13) = clng (16383) M_LONBITS (14) = CLNG (32767) m_lonbits (15) = CLNG (65535) m_lonbits (16) = CLNG (131071) m_lonbits (17) = CLNG (262143) m_lonbits (18) = CLNG (524287) M_LONBITS (19) = CLNG (1048575) M_LONBITS (20) = CLNG (2097151) m_lonbits (21) = CLng (4194303) m_lOnBits (22) = CLng (8388607) m_lOnBits (23) = CLng (16777215) m_lOnBits (24) = CLng (33554431) m_lOnBits (25) = CLng (67108863) m_lOnBits (26) = CLng (134217727) m_lOnBits (27) = CLNG (268435455) M_LONBITS (28) = CLNG (536870911) M_LONBITS (29) = CLNG (1073741823) M_LONBITS (30) = CLNG (2147483647) M _L2POWER (0) = clng (1) m_l2power (1) = clng (2) m_l2power (2) = clng (4) m_l2power (3) = clng (8) m_l2power (4) = CLNG (16) M_L2Power (5) = CLNG (32) M_L2POWER (6) = CLNG (64) M_L2Power (7) = ClNG (128) M_L2Power (8) = CLNG (256) M_L2Power (9) = CLNG (512) M_L2Power (10) = CLNG (1024) M_L2POWER (11) = clng (2048) m_l2power (12) = clng (4096) m_l2power (13) = clng (8192) m_l2power (14) = clng (16384) m_l2power (15) = CLNG (32768) M_L2Power (16) = clng (65536) M_L2POWER (17) = CLNG (131072) M_L2POWER (18) =
CLng (262144) m_l2Power (19) = CLng (524288) m_l2Power (20) = CLng (1048576) m_l2Power (21) = CLng (2097152) m_l2Power (22) = CLng (4194304) m_l2Power (23) = CLng (8388608) m_l2Power (24) = CLng (16777216) m_l2Power (25) = CLng (33554432) m_l2Power (26) = CLng (67108864) m_l2Power (27) = CLng (134217728) m_l2Power (28) = CLng (268435456) m_l2Power (29) = CLng (536870912) = CLNG (1073741824) DIM X DIM K DIM AA DIM BB DIM CC DD DIM A DIM B DIM C DIM D const S11 = 7 const S12 = 12 const S13 = 17 Const S14 = 22 Const S21 = 5 Const S22 = 9 const S23 = 14 const S24 = 20 const S31 = 4 const S32 = 11 const S33 = 16 const S34 = 23 const S41 = 6 const S42 = 10 Const S43 = 15 Const S44 = 21
X = converttowordArray (SMESSAGE) a = & h67452301 b = & hefcdab89 c = & h98badcfe d = & h10325476
For K = 0 to Ubound (x) Step 16 aa = a bb = b cc = C DD = D MD5_FF A, B, C, D, X (K 0), S11, & HD76AA478 MD5_FF D, A, B, C , X (k 1), S12, & HE8C7B756 MD5_FF C, D, A, B, X (K 2), S13, & H242070DB MD5_FF B, C, D, A, X (K 3), S14, & HC1BDCEEE MD5_FF A, B, C, D, X (K 4), S11, & HF57C0FAF MD5_FF D, A, B, C, X (K 5), S12, & H4787C62A MD5_FF C, D, A, B, X (K 6), S13, & HA8304613 MD5_FF B, C, D, A, X (K 7), S14, & HFD469501 MD5_FF A, B, C, D, X (K 8), S11, & H698098D8 MD5_FF D, A, B , C, X (K 9), S12, & H8B44F7AF MD5_FF C, D, A, B, X (K 10), S13, & HFFFF5BB1 MD5_FF B, C, D, A, X (k 11), S14, & H895CD7BE MD5_FF A, B, C, D, X (K 12), S11, & H6B901122 MD5_FF D, A, B, C, X (K 13), S12, & HFD987193 MD5_FF C, D, A, B, X ( K 14), S13, & HA679438E MD5_FF B, C, D, A, X (K 15), S14, & H49B40821 MD5_GG A, B, C, D, X (K 1), S21, & HF61E2562 MD5_GG D , A, B, C, X (K 6), S22, & HC040B340 MD5_GG C, D, A, B, X (K 11), S23, & H265E5A51 MD5_GG B, C, D, A, X (K 0 ), S24, & HE9B6C7AA MD5_GG A, B, C, D, X (K 5), S21, & HD62F105D MD5_GG D, A, B, C, X (K 10), S22, & H2441453 MD5_GG C, D, A, B, X (K 15), S23, & HD8A1E681 MD5_GG B, C, D, A, X (K 4), S24, & HE7D3FBC8 MD5_GG A, B, C, D, X (K 9), S21, & H21E1CDE6 MD5_GG D, A, B, C, X (K 14), S22, & HC33707D6 MD5_GG C, D, A, B, X (K 3), S23, &
HF4D50D87 MD5_GG B, C, D, A, X (K 8), S24, & H455A14ED MD5_GG A, B, C, D, X (K 13), S21, & HA9E3E905 MD5_GG D, A, B, C, X ( K 2), S22, & HFCEFA3F8 MD5_GG C, D, A, B, X (K 7), S23, & H676F02D9 MD5_GG B, C, D, A, X (K 12), S24, & H8D2A4C8A MD5_HH a, B , C, D, X (K 5), S31, & HFFFA3942 MD5_HH D, A, B, C, X (K 8), S32, & H8771F681 MD5_HH C, D, A, B, X (K 11), S33, & H6D9D6122 MD5_HH B, C, D, A, X (K 14), S34, & HFDE5380C MD5_HH A, B, C, D, X (K 1), S31, & HA4BEEA44 MD5_HH D, A, B, C, X (k 4), S32, & H4BDECFA9 MD5_HH C, D, A, B, X (K 7), S33, & HF6BB4B60 MD5_HH B, C, D, A, X (K 10), S34, & HBEBFBC70 MD5_HH A , B, C, D, X (K 13), S31, & H289B7EC6 MD5_HH D, A, B, C, X (K 0), S32, & HEAA127FA MD5_HH C, D, A, B, X (k 3 ), S33, & HD4EF3085 MD5_HH B, C, D, A, X (K 6), S34, & H4881D05 MD5_HH A, B, C, D, X (K 9), S31, & HD9D4D039 MD5_HH D, A, B, C, X (k 12), S32, & HE6DB99E5 MD5_HH C, D, A, B, X (K 15), S33, & H1FA27CF8 MD5_HH B, C, D, A, X (K 2), S34, & HC4AC5665 MD5_II A, B, C, D, X (k 0), S41, & HF4292244 MD5_II D, A, B, C, X (K 7), S42, & H432AFF97 MD5_II C, D, A, B, X (K 14), S43, & HAB9423A7 MD5_II B , C, D, A, X (K 5), S44, & HFC93A039 MD5_II A, B, C, D, X (K 12), S41, & H655B59C3 MD5_II D, A, B, C, X (K 3 ), S42, & H8F0CCC92 MD5_II C, D, A, B, X (K 10), S43, & HFFEFF47D MD5_II B, C, D, A, X (K