<% ' derived from the rsa data security, inc. md5 message-digest algorithm, ' as set out in the memo rfc1321. ' ' ' asp vbscript code for generating an md5 'digest' or 'signature' of a string. the ' md5 algorithm is one of the industry standard methods for generating digital ' signatures. it is generically known as a digest, digital signature, one-way ' encryption, hash or checksum algorithm. a common use for md5 is for password ' encryption as it is one-way in nature, that does not mean that your passwords ' are not free from a dictionary attack. ' ' this is 'free' software with the following restrictions: ' ' you may not redistribute this code as a 'sample' or 'demo'. however, you are free ' to use the source code in your own code, but you may not claim that you created ' the sample code. it is expressly forbidden to sell or profit from this source code ' other than by the knowledge gained or the enhanced value added by your own code. ' ' use of this software is also done so at your own risk. the code is supplied as ' is without warranty or guarantee of any kind. ' ' should you wish to commission some derivative work based on this code provided ' here, or any consultancy work, please do not hesitate to contact us. ' ' web site: http://www.frez.co.uk ' e-mail: [email protected]
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 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 &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 f(x, y, z) f = (x and y) or ((not x) and z) end function
private function g(x, y, z) g = (x and z) or (y and (not z)) end function
private function h(x, y, z) h = (x xor y xor z) end function
private function i(x, y, z) i = (y xor (x or (not z))) end function
private sub ff(a, b, c, d, x, s, ac) a = addunsigned(a, addunsigned(addunsigned(f(b, c, d), x), ac)) a = rotateleft(a, s) a = addunsigned(a, b) end sub
private sub gg(a, b, c, d, x, s, ac) a = addunsigned(a, addunsigned(addunsigned(g(b, c, d), x), ac)) a = rotateleft(a, s) a = addunsigned(a, b) end sub
private sub hh(a, b, c, d, x, s, ac) a = addunsigned(a, addunsigned(addunsigned(h(b, c, d), x), ac)) a = rotateleft(a, s) a = addunsigned(a, b) end sub
private sub ii(a, b, c, d, x, s, ac) a = addunsigned(a, addunsigned(addunsigned(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
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) dim x dim k dim aa dim bb dim cc dim dd dim a dim b dim c dim d
a = &h67452301 b = &hefcdab89 c = &h98badcfe d = &h10325476
for k = 0 to ubound(x) step 16 aa = a bb = b cc = c dd = d
ff a, b, c, d, x(k + 0), s11, &hd76aa478 ff d, a, b, c, x(k + 1), s12, &he8c7b756 ff c, d, a, b, x(k + 2), s13, &h242070db ff b, c, d, a, x(k + 3), s14, &hc1bdceee ff a, b, c, d, x(k + 4), s11, &hf57c0faf ff d, a, b, c, x(k + 5), s12, &h4787c62a ff c, d, a, b, x(k + 6), s13, &ha8304613 ff b, c, d, a, x(k + 7), s14, &hfd469501 ff a, b, c, d, x(k + 8), s11, &h698098d8 ff d, a, b, c, x(k + 9), s12, &h8b44f7af ff c, d, a, b, x(k + 10), s13, &hffff5bb1 ff b, c, d, a, x(k + 11), s14, &h895cd7be ff a, b, c, d, x(k + 12), s11, &h6b901122 ff d, a, b, c, x(k + 13), s12, &hfd987193 ff c, d, a, b, x(k + 14), s13, &ha679438e ff b, c, d, a, x(k + 15), s14, &h49b40821
gg a, b, c, d, x(k + 1), s21, &hf61e2562 gg d, a, b, c, x(k + 6), s22, &hc040b340 gg c, d, a, b, x(k + 11), s23, &h265e5a51 gg b, c, d, a, x(k + 0), s24, &he9b6c7aa gg a, b, c, d, x(k + 5), s21, &hd62f105d gg d, a, b, c, x(k + 10), s22, &h2441453 gg c, d, a, b, x(k + 15), s23, &hd8a1e681 gg b, c, d, a, x(k + 4), s24, &he7d3fbc8 gg a, b, c, d, x(k + 9), s21, &h21e1cde6 gg d, a, b, c, x(k + 14), s22, &hc33707d6 gg c, d, a, b, x(k + 3), s23, &hf4d50d87 gg b, c, d, a, x(k + 8), s24, &h455a14ed gg a, b, c, d, x(k + 13), s21, &ha9e3e905 gg d, a, b, c, x(k + 2), s22, &hfcefa3f8 gg c, d, a, b, x(k + 7), s23, &h676f02d9 gg b, c, d, a, x(k + 12), s24, &h8d2a4c8a
hh a, b, c, d, x(k + 5), s31, &hfffa3942 hh d, a, b, c, x(k + 8), s32, &h8771f681 hh c, d, a, b, x(k + 11), s33, &h6d9d6122 hh b, c, d, a, x(k + 14), s34, &hfde5380c hh a, b, c, d, x(k + 1), s31, &ha4beea44 hh d, a, b, c, x(k + 4), s32, &h4bdecfa9 hh c, d, a, b, x(k + 7), s33, &hf6bb4b60 hh b, c, d, a, x(k + 10), s34, &hbebfbc70 hh a, b, c, d, x(k + 13), s31, &h289b7ec6 hh d, a, b, c, x(k + 0), s32, &heaa127fa hh c, d, a, b, x(k + 3), s33, &hd4ef3085 hh b, c, d, a, x(k + 6), s34, &h4881d05 hh a, b, c, d, x(k + 9), s31, &hd9d4d039 hh d, a, b, c, x(k + 12), s32, &he6db99e5 hh c, d, a, b, x(k + 15), s33, &h1fa27cf8 hh b, c, d, a, x(k + 2), s34, &hc4ac5665
ii a, b, c, d, x(k + 0), s41, &hf4292244 ii d, a, b, c, x(k + 7), s42, &h432aff97 ii c, d, a, b, x(k + 14), s43, &hab9423a7 ii b, c, d, a, x(k + 5), s44, &hfc93a039 ii a, b, c, d, x(k + 12), s41, &h655b59c3 ii d, a, b, c, x(k + 3), s42, &h8f0ccc92 ii c, d, a, b, x(k + 10), s43, &hffeff47d ii b, c, d, a, x(k + 1), s44, &h85845dd1 ii a, b, c, d, x(k + 8), s41, &h6fa87e4f ii d, a, b, c, x(k + 15), s42, &hfe2ce6e0 ii c, d, a, b, x(k + 6), s43, &ha3014314 ii b, c, d, a, x(k + 13), s44, &h4e0811a1 ii a, b, c, d, x(k + 4), s41, &hf7537e82 ii d, a, b, c, x(k + 11), s42, &hbd3af235 ii c, d, a, b, x(k + 2), s43, &h2ad7d2bb 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 %>