<%
Private Const BITS_TO_A_BYTE = 8
Private Const BYTES_TO_A_WORD = 4
Private 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 = Then
If Lvalue and 1 then
LShift = &h80000000
Else
LShift = 0
End If
Exit function
ElseIf ishiftbits < 0 or ishiftbits >
Err.Raise 6
End If
if (Lvalue and M_l2power (31-ishiftbits)) Then
LShift = ((Lvalue and M_lonbits (+-(ishiftbits + 1))) * M_l2power (ishiftbits)) or &h80000000
Else
LShift = ((Lvalue and M_lonbits (31-ishiftbits)) * M_l2power (ishiftbits))
End If
End Function
Private Function Rshift (Lvalue, Ishiftbits)
If ishiftbits = 0 Then
Rshift = Lvalue
Exit function
ElseIf ishiftbits = Then
If Lvalue and &h80000000 then
Rshift = 1
Else
Rshift = 0
End If
Exit function
ElseIf ishiftbits < 0 or ishiftbits >
Err.Raise 6
End If
Rshift = (lvalue and &h7ffffffe) \ M_l2power (ishiftbits)
if (Lvalue and &h80000000) then
Rshift = (rshift or (&h40000000 \ 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 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 = 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 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 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 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_lonbits (6) = CLng (127)
M_lonbits (7) = CLng (255)
M_lonbits (8) = CLng (511)
M_lonbits (9) = CLng (1023)
M_lonbits (Ten) = CLng (2047)
M_lonbits (one) = CLng (4095)
M_lonbits () = CLng (8191)
M_lonbits (+) = CLng (16383)
M_lonbits (+) = CLng (32767)
M_lonbits () = CLng (65535)
M_lonbits (+) = CLng (131071)
M_lonbits (+) = CLng (262143)
M_lonbits (+) = CLng (524287)
M_lonbits (+) = CLng (1048575)
M_lonbits () = CLng (2097151)
M_lonbits (+) = CLng (4194303)
M_lonbits (+) = CLng (8388607)
M_lonbits (+) = CLng (16777215)
M_lonbits (+) = CLng (33554431)
M_lonbits (+) = CLng (67108863)
M_lonbits (+) = CLng (134217727)
M_lonbits (+) = CLng (268435455)
M_lonbits (+) = CLng (536870911)
M_lonbits = CLng (1073741823)
M_lonbits (+) = 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 (Ten) = CLng (1024)
M_l2power (one) = CLng (2048)
M_l2power () = CLng (4096)
M_l2power (+) = CLng (8192)
M_l2power (+) = CLng (16384)
M_l2power () = CLng (32768)
M_l2power (+) = CLng (65536)
M_l2power (+) = CLng (131072)
M_l2power (+) = CLng (262144)
M_l2power (+) = CLng (524288)
M_l2power () = CLng (1048576)
M_l2power (+) = CLng (2097152)
M_l2power (+) = CLng (4194304)
M_l2power (+) = CLng (8388608)
M_l2power (+) = CLng (16777216)
M_l2power (+) = CLng (33554432)
M_l2power (+) = CLng (67108864)
M_l2power (+) = CLng (134217728)
M_l2power (+) = CLng (268435456)
M_l2power = CLng (536870912)
M_l2power (+) = 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 + ten), S13, &HFFFF5BB1
Md5_ff B, C, D, A, X (K + a), S14, &h895cd7be
Md5_ff A, B, C, D, X (k + D), S11, &h6b901122
Md5_ff D, A, B, C, X (k + D), S12, &hfd987193
Md5_ff C, D, a, B, X (k +), S13, &ha679438e
Md5_ff B, C, D, A, X (K + a), 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 + a), 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 + ten), S22, &h2441453
Md5_gg C, D, a, B, X (k + a), 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 +), 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 + D), 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 + b), 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 + a), S33, &h6d9d6122
Md5_hh B, C, D, A, X (k +), 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 + ten), s34, &hbebfbc70
Md5_hh A, B, C, D, X (k + D), 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 + D), S32, &he6db99e5
Md5_hh C, D, a, B, X (k + a), 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 +), S43, &hab9423a7
Md5_ii B, C, D, A, X (K + 5), S44, &hfc93a039
Md5_ii A, B, C, D, X (k + D), S41, &H655B59C3
Md5_ii D, A, B, C, X (K + 3), S42, &h8f0ccc92
Md5_ii C, D, a, B, X (k + ten), 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 + a), S42, &HFE2CE6E0
Md5_ii C, D, a, B, X (k + 6), S43, &ha3014314
Md5_ii B, C, D, A, X (K + a), S44, &H4E0811A1
Md5_ii A, B, C, D, X (K + 4), S41, &hf7537e82
Md5_ii D, A, B, C, X (K + a), 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))
' 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_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 (Ten) = CLng (2047)
M_lonbits (one) = CLng (4095)
M_lonbits () = CLng (8191)
M_lonbits (+) = CLng (16383)
M_lonbits (+) = CLng (32767)
M_lonbits () = CLng (65535)
M_lonbits (+) = CLng (131071)
M_lonbits (+) = CLng (262143)
M_lonbits (+) = CLng (524287)
M_lonbits (+) = CLng (1048575)
M_lonbits () = CLng (2097151)
M_lonbits (+) = CLng (4194303)
M_lonbits (+) = CLng (8388607)
M_lonbits (+) = CLng (16777215)
M_lonbits (+) = CLng (33554431)
M_lonbits (+) = CLng (67108863)
M_lonbits (+) = CLng (134217727)
M_lonbits (+) = CLng (268435455)
M_lonbits (+) = CLng (536870911)
M_lonbits = CLng (1073741823)
M_lonbits (+) = 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 (Ten) = CLng (1024)
M_l2power (one) = CLng (2048)
M_l2power () = CLng (4096)
M_l2power (+) = CLng (8192)
M_l2power (+) = CLng (16384)
M_l2power () = CLng (32768)
M_l2power (+) = CLng (65536)
M_l2power (+) = CLng (131072)
M_l2power (+) = CLng (262144)
M_l2power (+) = CLng (524288)
M_l2power () = CLng (1048576)
M_l2power (+) = CLng (2097152)
M_l2power (+) = CLng (4194304)
M_l2power (+) = CLng (8388608)
M_l2power (+) = CLng (16777216)
M_l2power (+) = CLng (33554432)
M_l2power (+) = CLng (67108864)
M_l2power (+) = CLng (134217728)
M_l2power (+) = CLng (268435456)
M_l2power = CLng (536870912)
M_l2power (+) = 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 + ten), S13, &HFFFF5BB1
Md5_ff B, C, D, A, X (K + a), S14, &h895cd7be
Md5_ff A, B, C, D, X (k + D), S11, &h6b901122
Md5_ff D, A, B, C, X (k + D), S12, &hfd987193
Md5_ff C, D, a, B, X (k +), S13, &ha679438e
Md5_ff B, C, D, A, X (K + a), 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 + a), 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 + ten), S22, &h2441453
Md5_gg C, D, a, B, X (k + a), 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 +), 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 + D), 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 + b), 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 + a), S33, &h6d9d6122
Md5_hh B, C, D, A, X (k +), 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 + ten), s34, &hbebfbc70
Md5_hh A, B, C, D, X (k + D), 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 + D), S32, &he6db99e5
Md5_hh C, D, a, B, X (k + a), 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 +), S43, &hab9423a7
Md5_ii B, C, D, A, X (K + 5), S44, &hfc93a039
Md5_ii A, B, C, D, X (k + D), S41, &H655B59C3
Md5_ii D, A, B, C, X (K + 3), S42, &h8f0ccc92
Md5_ii C, D, a, B, X (k + ten), 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 + a), S42, &HFE2CE6E0
Md5_ii C, D, a, B, X (k + 6), S43, &ha3014314
Md5_ii B, C, D, A, X (K + a), S44, &H4E0811A1
Md5_ii A, B, C, D, X (K + 4), S41, &hf7537e82
Md5_ii D, A, B, C, X (K + a), 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))
Md5_16=lcase (Wordtohex (b) & Wordtohex (c)) ' I crop this to fit 16byte database password:d
Md5_16=ucase (MD5_16)
End Function
%>
ASP MD5 Cryptographic functions