<% Private Const BITS_TO_A_BYTE = 8Private Const BYTES_TO_A_WORD = 4Private Const BITS_TO_A_WORD = 32Private m_lOnBits (30) Private m_l2Power (30) Private Function LShift (lvalue, iShiftBits) If iShiftBits = 0 ThenLShift = lvalueExit FunctionElseIf iShiftBits = 31 ThenIf lvalue And 1 ThenLShift = & H80000000ElseLShift = 0End IfExit FunctionElseIf iShiftBits <0 Or iShiftBits> 31 ThenErr.Raise 6End IfIf (lvalue And m_l2Power (31 - iShiftBits)) ThenLShift = ((lvalue And m_lOnBits (31 - (iShiftBits 1))) * m_l2Power (iShiftBits)) Or & H80000000ElseLShift = ((lvalue And m_lOnBits (31 - iShiftBits)) * m_l2Power (iShiftBits)) End IfEnd FunctionPrivate Function rShift (lvalue, iShiftBits) If iShiftBits = 0 ThenRShift = lvalueExit FunctionElseIf iShiftBits = 31 ThenIf lvalue And & H80000000 ThenRShift = 1ElseRShift = 0End IfExit Functionelseif iShiftBits <0 or iShiftBits> 31 thenerr.raise 6nd IFRSHIFT = (LVALUE AND & H7FFFFFFE) / M_L2POWER (IshiftBits) IF (Lvalue and & H800000) Thenrshift = (RShift OR " 00000 / m_l2Power (iShiftBits - 1))) End IfEnd FunctionPrivate Function RotateLeft (lvalue, iShiftBits) RotateLeft = LShift (lvalue, iShiftBits) Or RShift (lvalue, (32 - iShiftBits)) End FunctionPrivate Function AddUnsigned (lX, lY) Dim lX4Dim lY4Dim lX8Dim lY8Dim lResultlX8 = lX And & H80000000lY8 = lY And & H80000000lX4 = lX And & H40000000lY4 = lY And & H40000000lResult = (lX And & H3FFFFFFF) (lY And & H3FFFFFFF) If lX4 And lY4 ThenlResult = lResult Xor & H80000000 Xor lX8 Xor lY8ElseIf lX4 Or lY4 ThenIf lResult And & H40000000 ThenLResult = LRESULT XOR &
HC0000000 Xor lX8 Xor lY8ElselResult = lResult Xor & H40000000 Xor lX8 Xor lY8End IfElselResult = lResult Xor lX8 Xor lY8End IfAddUnsigned = lResultEnd FunctionPrivate Function md5_F (x, y, z) md5_F = (x And y) Or ((Not x) And z) End FunctionPrivate Function MD5_G (X, Y, Z) MD5_G = (x and z) OR (Y AND (NOT Z)) End FunctionPrivate Function MD5_H (X, Y, Z) MD5_H = (x xor y xor z) end functionprivate function md5_i (x, y, z) MD5_i = (Y xor (x or (not z))) End functionPrivate 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 Subprivate Sub MD5_GG (A, B, C, D, X, S, AC) A = AddunSigned (A, Adunsigned (MD5_G (B, C, D), X), AC)) A = RotateLeft (A, S) a = addunsigned (A, b) end subsprivate 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 Subprivate Sub MD5_II (A, B, C, D, X, S, AC) a = addunsigned (A, Addunsigned (Addunsig ned (md5_I (b, c, d), x), ac)) a = RotateLeft (a, s) a = AddUnsigned (a, b) End SubPrivate Function ConvertToWordArray (sMessage) Dim lMessageLengthDim lNumberOfWordsDim lWordArray () Dim lBytePositionDim lByteCountDim lWordCountConst MODULUS_BITS = 512Const CONGRUENT_BITS = 448lMessageLength = 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 = 0LBytecount = 0do untric lbytecount> = LMESSAGELENGTHLWORDCOUNT = lbytecount / bytes_to_a_wordlbyteposition =
(LByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTElWordArray (lWordCount) = lWordArray (lWordCount) Or LShift (Asc (Mid (sMessage, lByteCount 1, 1)), lBytePosition) lByteCount = lByteCount 1LooplWordCount = lByteCount / BYTES_TO_A_WORDlBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTElWordArray (lWordCount) = lWordArray (lWordCount) Or LShift (& H80, lBytePosition) lWordArray (lNumberOfWords - 2) = LShift (lMessageLength, 3) lWordArray (lNumberOfWords - 1) = rShift (lMessageLength, 29) ConvertToWordArray = lWordArrayEnd FunctionPrivate Function WordToHex (lvalue ) Dim lByteDim lCountFor lCount = 0 To 3lByte = rShift (lvalue, lCount * BITS_TO_A_BYTE) And m_lOnBits (BITS_TO_A_BYTE - 1) WordToHex = WordToHex & Right ( "0" & Hex (lByte), 2) NextEnd FunctionPublic 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) = ClNBits (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) m_l2Power (30) = CLng (1073741824 ) DIM XDIM KDIM AADIM BBDIM CCDIM DDDIM ADIM BDIM CDIM DCONST S11 = 7Const S12 = 12const S13 = 17Const S14 = 22Const S21 = 5Const S22 = 9Const S23 = 14Const S24 = 20Const S31 = 4Const S32 = 11Const S33 = 16Const S34 = 23Const S41 = 6Const S42 = 10Const S43 = 15Const S44 = 21x = ConvertToWordArray (sMessage) a = & H67452301b = & HEFCDAB89c = & H98badcfed = & h10325476for k = 0 to ubound (x) step 16aa = abb = bcc = CDD = DMD5_FF A, B, C, D, X (k 0), S11, & HD76AA478MD5_FF D, A, B, C, X ( K 1), S12, & HE8C7B756MD5_FF C, D, A, B, X (K 2), S13, &
H242070DBMD5_FF B, C, D, A, X (K 3), S14, & HC1BDCEEMD5_FF A, B, C, D, X (K 4), S11, & HF57C0FAFMD5_FF D, A, B, C, X (K 5 ), S12, & H4787C62AMD5_FF C, D, A, B, X (K 6), S13, & HA8304613MD5_FF B, C, D, A, X (K 7), S14, & HFD469501MD5_FF A, B, C, D, X (k 8), S11, & H698098D8MD5_FF D, A, B, C, X (K 9), S12, & H8B44F7AFMD5_FF C, D, A, B, X (K 10), S13, & HFFFF5BB1MD5_FF B, C, D , A, X (k 11), S14, & H895CD7BEMD5_FF A, B, C, D, X (K 12), S11, & H6B901122MD5_FF D, A, B, C, X (K 13), S12, & HFD987193MD5_FF C , D, A, B, X (14), S13, & HA679438EMD5_FF B, C, D, A, X (K 15), S14, & H49B40821MD5_GG A, B, C, D, X (K 1), S21, & HF61E2562MD5_GG D, A, B, C, X (k 6), S22, & HC040B340MD5_GG C, D, A, B, X (K 11), S23, & H265E5A51MD5_GG B, C, D, A, X (K 0), S24, & HE9B6C7AAMD5_GG A, B, C, D, X (K 5), S21, & HD62F105DMD5_GG D, A, B, C, X (K 10), S22, & H2441453MD5_GG C, D, A, B , X (k 15), S23, & HD8A1E681MD5_GG B, C, D, A, X (K 4), S24, & HE7D3FBC8MD5_GG A, B, C, D, X (K 9), S21, & H21E1CDE6MD5_GG D, A , B, C, X (K 14), S22, & HC33707D6MD5_GG C, D, A, B, X (K 3), S23, & HF4D50D87MD5_GG B, C, D, A, X (K 8), S24, & H455A14EDMD5_GG A, B, C, D, X (K 13), S21, & HA9E3E905MD5_GG D, A, B, C, X (K 2), S22, & HFCEFA3F8MD5_GG C, D, A, B, X (K 7), S23 & H676F02D9MD5_GG B, C, D, A, X (K 12), S24, & H8D2A4C8AMD5_HH A, B, C, D, X (K 5), S31, & HFFFA3942MD5_HH D, A, B, C, X (K 8), S32, & H8771F681MD5_HH C, D, A, B, X (K 11), S33, & H6D9D6122MD5_HH B, C, D, A, X (K 14), S34, &
HFDE5380CMD5_HH A, B, C, D, X (K 1), S31, & HA4BEEA44MD5_HH D, A, B, C, X (K 4), S32, & H4BDECFA9MD5_HH C, D, A, B, X (k 7 ), S33, & HF6BB4B60MD5_HH B, C, D, A, X (K 10), S34, & HBebfbc70md5_hh A, B, C, D, X (K 13), S31, & H289B7EC6MD5_HH D, A, B, C, X (k 0), S32, & HEAA127FAMD5_HH C, D, A, B, X (K 3), S33, & HD4EF3085MD5_HH B, C, D, A, X (K 6), S34, & H4881D05MD5_HH A, B, C , D, X (k 9), S31, & HD9D4D039MD5_HH D, A, B, C, X (K 12), S32, & HE6DB99E5MD5_HH C, D, A, B, X (K 15), S33, & H1FA27CF8MD5_HH B , C, D, A, X (2), S34, & HC4AC5665MD5_II A, B, C, D, X (K 0), S41, & HF4292244MD5_II D, A, B, C, X (K 7), S42, & H432AFF97MD5_II C, D, A, B, X (K 14), S43, & HAB9423A7MD5_II B, C, D, A, X (K 5), S44, & HFC93A039MD5_II A, B, C, D, X (K 12), S41, & H655B59C3MD5_II D, A, B, C, X (K 3), S42, & H8F0CCC92MD5_II C, D, A, B, X (K 10), S43, & Hffeff47DMD5_II B, C, D, A X (k 1), S44, & H85845DD1MD5_II A, B, C, D, X (K 8), S41, & H6FA87E4FMD5_II D, A, B, C, X (K 15), S42, & HFE2CE6E0MD5_II C, D , A, B, X (k 6), S43, & HA3014314MD5_II B, C, D, A, X (K 13), S44, & H4E0811A1MD5_II A, B, C, D, X (K 4), S41, & HF7537E82MD5_II D, A, B, C, X (K 11), S42, & HBD3AF235MD5_II C, D, A, B, X (K 2), S43, & H2AD7D2BBMD5_II B, C, D, A, X (K 9), S44 , & Heb86d391a = addunsigned (a, aa) b = addunsigned (b, bb) c = addunsigned (c, cc) d = addunsigned (d, dd) Nextmd5 = LCase (WordTohex (a) & WordTohex (B) & WordTohex (C ) & WordTohex (D)) 'MD5 = LCase (WordTohex (B) & WordToHex (C))'