var password = $ (' #password '). Val ();//Gets the value of the Password box
var passwordMD5 = MD5 (password);//Call MD5, pass in password, return MD5 encrypted string
function MD5 (string) {
function Md5_rotateleft (LValue, ishiftbits) {
Return (lValue << ishiftbits) | (LValue >>> (32-ishiftbits));
}
function md5_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 Md5_f (x, Y, z) {
Return (x & y) | ((~x) & Z);
}
function Md5_g (x, Y, z) {
Return (X & Z) | (Y & (~z));
}
function Md5_h (x, Y, z) {
return (x ^ y ^ z);
}
function md5_i (x, Y, z) {
Return (y ^ (x | (~z)));
}
function Md5_ff (A, B, C, D, X, S, ac) {
A = md5_addunsigned (A, md5_addunsigned (md5_addunsigned (Md5_f (b, C, D), x), AC));
Return md5_addunsigned (Md5_rotateleft (A, s), b);
};
function Md5_gg (A, B, C, D, X, S, ac) {
A = md5_addunsigned (A, md5_addunsigned (md5_addunsigned (Md5_g (b, C, D), x), AC));
Return md5_addunsigned (Md5_rotateleft (A, s), b);
};
function Md5_hh (A, B, C, D, X, S, ac) {
A = md5_addunsigned (A, md5_addunsigned (md5_addunsigned (Md5_h (b, C, D), x), AC));
Return md5_addunsigned (Md5_rotateleft (A, s), b);
};
function Md5_ii (A, B, C, D, X, S, ac) {
A = md5_addunsigned (A, md5_addunsigned (md5_addunsigned (md5_i (b, C, D), x), AC));
Return md5_addunsigned (Md5_rotateleft (A, s), b);
};
function Md5_converttowordarray (string) {
var Lwordcount;
var lmessagelength = string.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] | (String.charcodeat (Lbytecount) << lbyteposition));
lbytecount++;
}
Lwordcount = (Lbytecount-(lbytecount% 4))/4;
lbyteposition = (lbytecount% 4) * 8;
Lwordarray[lwordcount] = Lwordarray[lwordcount] | (0x80 << lbyteposition);
Lwordarray[lnumberofwords-2] = lmessagelength << 3;
LWORDARRAY[LNUMBEROFWORDS-1] = lmessagelength >>> 29;
return lwordarray;
};
function Md5_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;
};
function Md5_utf8encode (string) {
String = String.Replace (/\r\n/g, "\ n");
var utftext = "";
for (var n = 0; n < string.length; n++) {
var c = string.charcodeat (n);
if (c < 128) {
Utftext + = String.fromCharCode (c);
} else if ((C > 127) && (C < 2048)) {
Utftext + = String.fromCharCode ((c >> 6) | 192);
Utftext + = String.fromCharCode ((C & 63) | 128);
} else {
Utftext + = String.fromCharCode ((c >> 12) | 224);
Utftext + = String.fromCharCode (((c >> 6) & 63) | 128);
Utftext + = String.fromCharCode ((C & 63) | 128);
}
}
return utftext;
};
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;
String = Md5_utf8encode (string);
x = Md5_converttowordarray (string);
A = 0x67452301;
b = 0xefcdab89;
c = 0x98badcfe;
D = 0x10325476;
for (k = 0; k < x.length; k + = 16) {
AA = A;
BB = b;
CC = C;
DD = D;
A = Md5_ff (A, B, C, D, X[k + 0], S11, 0xd76aa478);
D = md5_ff (d, a, B, C, x[k + 1], S12, 0xe8c7b756);
c = md5_ff (c, D, a, B, X[k + 2], S13, 0x242070db);
b = md5_ff (b, C, D, a, X[k + 3], S14, 0xc1bdceee);
A = Md5_ff (A, B, C, D, X[k + 4], S11, 0XF57C0FAF);
D = md5_ff (d, a, B, C, X[k + 5], S12, 0x4787c62a);
c = md5_ff (c, D, a, B, X[k + 6], S13, 0xa8304613);
b = md5_ff (b, C, D, a, x[k + 7], S14, 0xfd469501);
A = Md5_ff (A, B, C, D, X[k + 8], S11, 0X698098D8);
D = md5_ff (d, a, B, C, x[k + 9], S12, 0X8B44F7AF);
c = md5_ff (c, D, a, B, X[k + ten], S13, 0XFFFF5BB1);
b = md5_ff (b, C, D, a, x[k + one), S14, 0x895cd7be);
A = Md5_ff (A, B, C, D, X[k +), S11, 0x6b901122);
D = md5_ff (d, a, B, C, X[k +], S12, 0xfd987193);
c = md5_ff (c, D, a, B, x[k + +), S13, 0xa679438e);
b = md5_ff (b, C, D, a, x[k + [], S14, 0x49b40821);
A = Md5_gg (A, B, C, D, X[k + 1], S21, 0xf61e2562);
D = Md5_gg (d, a, B, C, x[k + 6], S22, 0xc040b340);
c = Md5_gg (c, D, a, B, X[k + one), S23, 0x265e5a51);
b = Md5_gg (b, C, D, a, x[k + 0], S24, 0XE9B6C7AA);
A = Md5_gg (A, B, C, D, X[k + 5], S21, 0xd62f105d);
D = Md5_gg (d, a, B, C, X[k + ten], S22, 0x2441453);
c = Md5_gg (c, D, a, B, x[k + [], S23, 0xd8a1e681);
b = Md5_gg (b, C, D, a, X[k + 4], S24, 0XE7D3FBC8);
A = Md5_gg (A, B, C, D, X[k + 9], S21, 0x21e1cde6);
D = Md5_gg (d, a, B, C, x[k + +), S22, 0XC33707D6);
c = Md5_gg (c, D, a, B, X[k + 3], S23, 0xf4d50d87);
b = Md5_gg (b, C, D, a, x[k + 8], S24, 0x455a14ed);
A = Md5_gg (A, B, C, D, X[k +), S21, 0xa9e3e905);
D = Md5_gg (d, a, B, C, X[k + 2], S22, 0XFCEFA3F8);
c = Md5_gg (c, D, a, B, X[k + 7], S23, 0X676F02D9);
b = Md5_gg (b, C, D, a, X[k +), S24, 0x8d2a4c8a);
A = Md5_hh (A, B, C, D, X[k + 5], S31, 0xfffa3942);
D = md5_hh (d, a, B, C, X[k + 8], S32, 0x8771f681);
c = md5_hh (c, D, a, B, X[k + one), S33, 0x6d9d6122);
b = md5_hh (b, C, D, a, x[k + +), S34, 0xfde5380c);
A = Md5_hh (A, B, C, D, X[k + 1], S31, 0xa4beea44);
D = md5_hh (d, a, B, C, X[k + 4], S32, 0x4bdecfa9);
c = md5_hh (c, D, a, B, X[k + 7], S33, 0xf6bb4b60);
b = md5_hh (b, C, D, a, X[k + ten], S34, 0XBEBFBC70);
A = Md5_hh (A, B, C, D, X[k +), S31, 0X289B7EC6);
D = md5_hh (d, a, B, c, X[k + 0], S32, 0XEAA127FA);
c = md5_hh (c, D, a, B, X[k + 3], S33, 0xd4ef3085);
b = md5_hh (b, C, D, a, x[k + 6], S34, 0X4881D05);
A = Md5_hh (A, B, C, D, X[k + 9], S31, 0xd9d4d039);
D = md5_hh (d, a, B, C, X[k +), S32, 0xe6db99e5);
c = md5_hh (c, D, a, B, x[k + [], S33, 0X1FA27CF8);
b = md5_hh (b, C, D, a, X[k + 2], S34, 0xc4ac5665);
A = Md5_ii (A, B, C, D, X[k + 0], S41, 0xf4292244);
D = Md5_ii (d, a, B, C, x[k + 7], S42, 0X432AFF97);
c = Md5_ii (c, D, a, B, x[k + +), S43, 0XAB9423A7);
b = Md5_ii (b, C, D, a, X[k + 5], S44, 0xfc93a039);
A = Md5_ii (A, B, C, D, X[k +), S41, 0X655B59C3);
D = Md5_ii (d, a, B, C, X[k + 3], S42, 0x8f0ccc92);
c = Md5_ii (c, D, a, B, X[k + ten], S43, 0xffeff47d);
b = Md5_ii (b, C, D, a, x[k + 1], S44, 0X85845DD1);
A = Md5_ii (A, B, C, D, X[k + 8], S41, 0x6fa87e4f);
D = Md5_ii (d, a, B, C, X[k + [], S42, 0XFE2CE6E0);
c = Md5_ii (c, D, a, B, X[k + 6], S43, 0xa3014314);
b = Md5_ii (b, C, D, a, x[k +], S44, 0X4E0811A1);
A = Md5_ii (A, B, C, D, X[k + 4], S41, 0xf7537e82);
D = Md5_ii (d, a, B, C, x[k + one), S42, 0xbd3af235);
c = Md5_ii (c, D, a, B, X[k + 2], S43, 0X2AD7D2BB);
b = Md5_ii (b, C, D, a, x[k + 9], S44, 0xeb86d391);
A = md5_addunsigned (A, AA);
b = md5_addunsigned (b, BB);
c = md5_addunsigned (c, CC);
D = md5_addunsigned (d, DD);
}
Return (Md5_wordtohex (a) + Md5_wordtohex (b) + Md5_wordtohex (c) + Md5_wordtohex (d)). toLowerCase ();
}
MD5 encryption (front-end JS)