VBS MD5 package class

xiaoxiao2021-03-06  37

Application example:

<%

e_pws = "abc"

DIM OBJMD5, E_PWS_ENC

Set Objmd5 ​​= New CLSMD5

e_PWS_ENC = Objmd5.md5 (e_PWS)

%>

MD5.ASP file:

<%

Class CLSMD5

PRIVATE BITS_TO_A_BYTE

PRIVATE BYTES_TO_A_WORD

PRIVATE BITS_TO_A_WORD

Private m_lonbits (30)

Private M_L2Power (30)

Private sub coplass_initialize ()

BITS_TO_A_BYTE = 8

BYTES_TO_A_WORD = 4

BITS_TO_A_WORD = 32

End Sub

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) * m_l2power (iShiftBits))

END IF

END 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 (& H400000 / M_L2Power (IshiftBits - 1)))

END IF

END 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 LX8DIM 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 IF

Addunsigned = LRESULT

END 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, C, 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, C, D), X), AC)

a = rotateleft (a, s)

A = addunsigned (a, b)

End Sub

Private function convertToWordArray (SMESSAGE)

Dim LMessageLength

Dim lnumberofwords

Dim lwordArray ()

Dim lbytepositiondim 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 mod bytes_to_a_word) * bits_to_a_byte

LWordArray (LWORDCOUNT) OR LSHIFT (ASC (MID (SMESSAGE, LBYTECUNT 1, 1)), LBYTEPOSITION

lbytecount = lbytecount 1

Loop

LWORDCOUNT = lbytecount / bytes_to_a_word

LbytePosition = (lbytecount mod bytes_to_a_word) * bits_to_a_byte

LWordArray (lwordcount) = lwordArray (lwordcount) or lshift (& H80, lbyteposition)

LWordArray (lnumberofwords - 2) = lshift (LMessageLength, 3)

LWordArray (Lnumberofwords - 1) = RSHIFT (LMessageLength, 29)

ConvertToWordArray = LWORDARRAY

END 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)

NEXT

END 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_lonbit (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_lonbit (27) = CLNG (268435455)

M_lonbit (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

DIM 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, & H2441453MD5_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_HHH B, C, D, A, X (k 14), S34, & HFDE5380C

MD5_HH A, B, C, D, X (k 1), S31, & Ha4bee44

MD5_HH D, A, B, C, X (K 4), S32, & H4BDECFA9

MD5_HH C, D, A, B, X (K 7), S33, & HF6BB4B60

MD5_HHH 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_HHH 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_HHH 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, & H8F0CCC92MD5_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, & HEB86D391

A = 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))

END FUNCTION

END CLASS

%>

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

New Post(0)