MD5 encrypted functions and examples in ASP

zhaozj2021-02-16  76

'MD5 encryption algorithm 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 <0 or ishiftbits> 31 then err if exit function elseif ishiftbits. 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 & h3ffffff) (Ly and & H3FFFFFF)

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 ifaddunsigned = LRESULTEND FUNCTION

Private 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 sub

Private Function ConvertToWordArray (SMESSAGE) DIM LMESSAGELENGTH DIM LNUMBEROFWORDS DIM LWORDARRAY () DIM LBYTEPSITION DIM LBYTECUNT 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 mod bytes_to_a_word) * bits_to_a_byte lwordarray (lwordcount) = lwordarray (lwordcount) or lshift (asc (mid (smessage, lbytecount 1, 1)), lbyteposition) lbytecount = 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 (LMESSAGALELENGTH, 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_l2p Ower (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 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 = twenty one

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 M D5_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, & H8D2A4C8AMD5_HH A, B, C, D, X (K 5), S31, & HFFA3942 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, & HF429244 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, & H65559C3 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 1), S44 & H85845DD1 MD5_II A, B, C, D, X (K 8), S41, & H6FA87E4F MD5_II D, A, B, C, X (K 15), S42, & HFE2CE6E0 MD5_II C, D, A, B, X (k 6), S43, & HA3014314 MD5_II B, C, D, A, X (K 13), S44, & H4E0811A1 MD5_II A, B, C, D, X (K 4), S41, & HF7537E82 MD5_II D, A, B, C, X (K 11), S42, & HBD3AF235 MD5_II C, D, A, B, X (K 2), S43, & H2AD7D2BB MD5_II B, C, D, A, X (K 9) , S44, & HEB86D391A = Addunsigned (AA) B = AddunSigned (b, bb) C = addunsigned (C, CC) D = AddunSigned (D, DD) Next MD5 = LCase (WordTohex (a) & WordTohex (B) & Wordtohex (C) & WordTohex (D)) 'MD5 = LCase (WordTohex (B) & WordTohex (C))' i crop this to fit 16byte Database Password : D MD5 = ucase (md5) End Function

Public function MD5_16 (SMESSAGE) M_LONBITS (0) = clng (1) m_lonbits (1) = ClNG (3) M_LONBITS (2) = clng (7) M_Lonbit 4 = CLNG (15) M_Lonbit 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) M_L2Power (30) = 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 = twenty one

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 M D5_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, & H8D2A4C8AMD5_HH A, B, C, D, X (K 5), S31, & HFFA3942 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, & HF429244 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, & H65559C3 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 1), S44 & H85845DD1 MD5_II A, B, C, D, X (K 8), S41, & H6FA87E4F MD5_II D, A, B, C, X (K 15), S42, & HFE2CE6E0 MD5_II C, D, A, B, X (k 6), S43, & HA3014314 MD5_II B, C, D, A, X (K 13), S44, & H4E0811A1 MD5_II A, B, C, D, X (K 4), S41, & HF7537E82 MD5_II D, A, B, C, X (K 11), S42, & HBD3AF235 MD5_II C, D, A, B, X (K 2), S43, & H2AD7D2BB MD5_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) Next 'md5 = lcase (WordTohex (a) & WordTohex (B) & Wordtohex (C) & WordTohex (D)) MD5_16 = LCase (WordTohex (B) & WordToHex (C)) 'i crop this to fit 16byte database passw ORD: D MD5_16 = ucase (md5_16) end function

'Quote: Get the MD5 encryption value of Password

Password = MD5 (Password)

转载请注明原文地址:https://www.9cbs.com/read-15879.html

New Post(0)