Reprint the essence of a forgotten source [MD5 encrypted JavaScript implementation Example]

Source: Internet
Author: User
Tags md5
/* 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<<ishiftbits) | (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);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.