/* md5 message-digest algorithm - javascript ' modification history: ' 1.0 16-feb-2001 - phil fresle (sales@frez.co.uk) - initial version (vb/asp code) ' 1.0 21-feb-2001 - enrico mosanghini (erik504@yahoo.com) - javascript porting */ function md5(smessage) { function rotateleft(lvalue, ishiftbits) { return (lvalue<>>(32-ishiftbits)); } function addunsigned(lx,ly) { var lx4,ly4,lx8,ly8,lresult; lx8 = (lx & 0x80000000); ly8 = (ly & 0x80000000); lx4 = (lx & 0x40000000); ly4 = (ly & 0x40000000); lresult = (lx & 0x3fffffff)+(ly & 0x3fffffff); if (lx4 & ly4) { return (lresult ^ 0x80000000 ^ lx8 ^ ly8); } if (lx4 | ly4) { if (lresult & 0x40000000) { return (lresult ^ 0xc0000000 ^ lx8 ^ ly8); } else { return (lresult ^ 0x40000000 ^ lx8 ^ ly8); } } else { return (lresult ^ lx8 ^ ly8); } } function f(x,y,z) { return (x & y) | ((~x) & z); } function g(x,y,z) { return (x & z) | (y & (~z)); } function h(x,y,z) { return (x ^ y ^ z); } function i(x,y,z) { return (y ^ (x | (~z))); } function ff(a,b,c,d,x,s,ac) { a = addunsigned(a, addunsigned(addunsigned(f(b, c, d), x), ac)); return addunsigned(rotateleft(a, s), b); } function gg(a,b,c,d,x,s,ac) { a = addunsigned(a, addunsigned(addunsigned(g(b, c, d), x), ac)); return addunsigned(rotateleft(a, s), b); } function hh(a,b,c,d,x,s,ac) { a = addunsigned(a, addunsigned(addunsigned(h(b, c, d), x), ac)); return addunsigned(rotateleft(a, s), b); } function ii(a,b,c,d,x,s,ac) { a = addunsigned(a, addunsigned(addunsigned(i(b, c, d), x), ac)); return addunsigned(rotateleft(a, s), b); } function converttowordarray(smessage) { var lwordcount; var lmessagelength = smessage.length; var lnumberofwords_temp1=lmessagelength + 8; var lnumberofwords_temp2=(lnumberofwords_temp1-(lnumberofwords_temp1 % 64))/64; var lnumberofwords = (lnumberofwords_temp2+1)*16; var lwordarray=array(lnumberofwords-1); var lbyteposition = 0; var lbytecount = 0; while ( lbytecount < lmessagelength ) { lwordcount = (lbytecount-(lbytecount % 4))/4; lbyteposition = (lbytecount % 4)*8; lwordarray[lwordcount] = (lwordarray[lwordcount] | (smessage.charcodeat(lbytecount)<>>29; return lwordarray; } function wordtohex(lvalue) { var wordtohexvalue="",wordtohexvalue_temp="",lbyte,lcount; for (lcount = 0; lcount<=3; lcount++) { lbyte = (lvalue>>>(lcount*8)) & 255; wordtohexvalue_temp = "0" + lbyte.tostring(16); wordtohexvalue = wordtohexvalue + wordtohexvalue_temp.substr(wordtohexvalue_temp.length-2,2); } return wordtohexvalue; } var x=array(); var k,aa,bb,cc,dd,a,b,c,d var s11=7, s12=12, s13=17, s14=22; var s21=5, s22=9 , s23=14, s24=20; var s31=4, s32=11, s33=16, s34=23; var s41=6, s42=10, s43=15, s44=21; // steps 1 and 2. append padding bits and length and convert to words x = converttowordarray(smessage); // step 3. initialise a = 0x67452301; b = 0xefcdab89; c = 0x98badcfe; d = 0x10325476; // step 4. process the message in 16-word blocks for (k=0; k