The "Go" JavaScript MD5 the same value as the Java messagedigest encryption

Source: Internet
Author: User

function integer (n) {return n% (0xffffffff+1);  }function SHR (A, b) {A=integer (a);  B=integer (b);    if (a-0x80000000>=0) {a=a%0x80000000;    a>>=b;  A+=0x40000000>> (b-1);  } else a>>=b; return A;}  function Shl1 (a) {a=a%0x80000000;    if (a&0x40000000==0x40000000) {a-=0x40000000;    a*=2;  a+=0x80000000;  } else a*=2; return A;}  function SHL (A, b) {A=integer (a);  B=integer (b);  for (Var i=0;i<b;i++) a=shl1 (a); return A;}  function and (A, b) {A=integer (a);  B=integer (b);  var t1= (a-0x80000000);  var t2= (b-0x80000000);    if (t1>=0) if (t2>=0) return ((T1&AMP;T2) +0x80000000);  else return (T1&AMP;B);    else if (t2>=0) return (A&AMP;T2); else return (A&AMP;B);}  function or (a, b) {A=integer (a);  B=integer (b);  var t1= (a-0x80000000);  var t2= (b-0x80000000);    if (t1>=0) if (t2>=0) return ((T1|T2) +0x80000000);  else return ((t1|b) +0x80000000); else if (t2>=0) return ((A|T2) +0x80000000); else return (a|b);}  Function Xor (A, b) {A=integer (a);  B=integer (b);  var t1= (a-0x80000000);  var t2= (b-0x80000000);    if (t1>=0) if (t2>=0) return (T1^T2);  else return ((t1^b) +0x80000000);    else if (t2>=0) return ((A^T2) +0x80000000); else return (A^B);}  Function not (a) {A=integer (a); return (0XFFFFFFFF-A);}    /* D¨|but de l ' algorithme */var state = new Array (4);        var count = new Array (2);        Count[0] = 0;    COUNT[1] = 0;    var buffer = new Array (64);    var transformbuffer = new Array (16);    var digestbits = new Array (16);    var S11 = 7;    var S12 = 12;    var S13 = 17;    var S14 = 22;    var S21 = 5;    var S22 = 9;    var S23 = 14;    var S24 = 20;    var S31 = 4;    var S32 = 11;    var S33 = 16;    var S34 = 23;    var S41 = 6;    var S42 = 10;    var S43 = 15;    var S44 = 21;    function F (x, y, N, z) {return or (and (Y), and (not (×), z)); The function G (x, Y, z) {return or (X,z), and (Y,not (z)));    } function H (x, z) {return xor (XOR (x, y), z);    } function I (x, Y, z) {return xor (Y, or (×, not (z)));    } function Rotateleft (a,n) {return or (SHL (A, N), (SHR (A, (32-n)));        } function FF (A,B,C,D,X,S,AC) {a = A+f (b, C, D) + x + ac;        A = Rotateleft (a, s);        A = A+b;    return A;        } function GG (A,B,C,D,X,S,AC) {a = A+g (b, C, D) +x + ac;        A = Rotateleft (a, s);        A = A+b;    return A;        } function HH (A,B,C,D,X,S,AC) {a = A+h (b, C, D) + x + ac;        A = Rotateleft (a, s);        A = A+b;    return A;        } function II (A,B,C,D,X,S,AC) {a = A+i (b, C, D) + x + ac;        A = Rotateleft (a, s);        A = A+b;    return A;        } function transform (buf,offset) {var a=0, b=0, c=0, d=0;        var x = Transformbuffer;        A = state[0];        b = state[1];        c = state[2];        d = state[3]; for (i = 0; i < i++) {X[i] = and (buf[i*4+OFFSET],0XFF);            for (j = 1; j < 4; J + +) {X[I]+=SHL (and (Buf[i*4+j+offset], 0xff), J * 8); }}/* Tour 1 */a = FF (A, B, C, D, x[0], S11, 0xd76aa478); /* 1 */d = FF (d, a, B, C, x[1], S12, 0xe8c7b756); /* 2 */c = FF (c, D, a, B, x[2], S13, 0x242070db); /* 3 */b = FF (b, C, D, A, x[3], S14, 0xc1bdceee); /* 4 */a = FF (A, B, C, D, x[4], S11, 0XF57C0FAF); /* 5 */d = FF (d, a, B, C, x[5], S12, 0x4787c62a); /* 6 */c = FF (c, D, a, B, x[6], S13, 0xa8304613); /* 7 */b = FF (b, C, D, A, x[7], S14, 0xfd469501); /* 8 */a = FF (A, B, C, D, x[8], S11, 0X698098D8); /* 9 */d = FF (d, a, B, C, x[9], S12, 0X8B44F7AF); /* Ten */c = FF (c, D, a, B, x[10], S13, 0XFFFF5BB1); /* each */b = FF (b, C, D, A, x[11], S14, 0x895cd7be); /* */A = FF (A, B, C, D, X[12], S11, 0x6b901122); /* */d = FF (d, a, B, C, x[13], S12, 0xfd987193); /* */C = FF (c, D, a, B, x[14], S13, 0xa679438e); /* */b = FF (b, C, D, A, x[15], S14, 0x49b40821); /* * */* Tour 2 */a = GG (A, B, C, D, x[1], S21, 0xf61e2562); /* * +/d = GG (d, a, B, C, x[6], S22, 0xc040b340); /* */C = GG (c, D, a, B, x[11], S23, 0x265e5a51); /* * +/b = GG (b, C, D, A, x[0], S24, 0XE9B6C7AA); /* */A = GG (A, B, C, D, x[5], S21, 0xd62f105d); /* */d = GG (d, a, B, C, x[10], S22, 0x2441453); /* */C = GG (c, D, a, B, x[15], S23, 0xd8a1e681); /* * */b = GG (b, C, D, A, x[4], S24, 0XE7D3FBC8); /* + * a = GG (A, B, C, D, x[9], S21, 0x21e1cde6); /* */d = GG (d, a, B, C, x[14], S22, 0XC33707D6); /* +/C = GG (c, D, a, B, x[3], S23, 0xf4d50d87); /* * +/b = GG (b, C, D, A, x[8], S24, 0x455a14ed); /* * * a = GG (A, B, C, D, X[13], S21, 0xa9e3e905); /* */d = GG (d, a, B, C, X[2], S22, 0XFCEFA3F8); /* +/C = GG (c, D, a, B, x[7], S23, 0X676F02D9); /* */b = GG (b, C, D, A, x[12], S24, 0x8d2a4c8a); /* +/* Tour 3 */a = HH (A, B, C, D, x[5], S31, 0xfffa3942); /* */d = HH (d, a, B, C, x[8], S32, 0x8771f681); /* */C = HH (c, D, a, B, x[11], S33, 0x6d9d6122); /* * +/b = HH (b, C, D, A, x[14], S34, 0xfde5380c); /* */A = HH (A, B, C, D, x[1], S31, 0xa4beea44); /* PNS */d = HH (d, a, B, C, x[4], S32, 0x4bdecfa9); /* * +/C = HH (c, D, a, B, x[7], S33, 0xf6bb4b60); /* * All-in-B = HH (b, C, D, A, x[10], S34, 0XBEBFBC70); /* + * a = HH (A, B, C, D, X[13], S31, 0X289B7EC6); /* */d = HH (d, a, B, C, x[0], S32, 0XEAA127FA); /* */C = HH (c, D, a, B, x[3], S33, 0xd4ef3085); /* + */b = HH (b, C, D, A, x[6], S34, 0X4881D05); /* * */a = HH (A, B, C, D, x[9], S31, 0xd9d4d039); /* */d = HH (d, A, B, C, x[12], S32, 0xe6db99e5); /* * +/C = HH (c, D, a, B, x[15], S33, 0X1FA27CF8); /* * */b = HH (b, C, D, A, x[2], S34, 0xc4ac5665); /* * *//* Tour 4 */a = II (A, B, C, D, x[0], S41, 0xf4292244); /* */d = II (d, a, B, C, x[7], S42, 0X432AFF97); /* */C = II (c, D, a, B, x[14], S43, 0XAB9423A7); /* Wuyi */b = II (b, C, D, A, x[5], S44, 0xfc93a039); /* */A = II (A, B, C, D, X[12], S41, 0X655B59C3); /* +/d = II (d, a, B, C, x[3], S42, 0x8f0ccc92); /* + */c = II (c, D, a, B, x[10], S43, 0xffeff47d); /* * */b = II (b, C, D, A, x[1], S44, 0X85845DD1); /* * * * a = II (A, B, C, D, x[8], S41, 0x6fa87e4f); /* (+/-)/d = II (d, a, B, C, x[15], S42, 0XFE2CE6E0); /* + +/c = II (c, D, a, B, x[6], S43, 0xa3014314); /* *//b = II (b, C, D, A, x[13], S44, 0X4E0811A1); /* * a = II (A, B, C, D, x[4], S41, 0xf7537e82);      /* 61 */  D = II (d, a, B, C, x[11], S42, 0xbd3af235); /* * +/C = II (c, D, a, B, x[2], S43, 0X2AD7D2BB); /* N/b = II (b, C, D, A, x[9], S44, 0xeb86d391);        /* * */state[0] +=a;        STATE[1] +=b;        STATE[2] +=c;    STATE[3] +=d;       }/* Avec l ' initialisation de dobbertin:state[0] = 0x12ac2375;       STATE[1] = 0x3b341042;       STATE[2] = 0x5f62b97c;       STATE[3] = 0x4ba763ed; S ' il y a une collision:begin 644 Message1 m7mh=jo6_>mg! X?! 51$) w,cxv! A "= (!       Ar71,<x ' y-iit9^z&8l$2n ' y*y:r.; 39gik9>tf$w ()/mehr%c4:g1r:q "= ' End begin 644 Message2 m7mh=jo6_>mg! X?! 51$) w,cxv! A "= (!       Ar71,<x ' y-iit9^z&8l$2n ' y*y:r.;        39gik9>tf$w ()/mehrec4:g1r:q "= ' End */function init () {count[0]=count[1] = 0;        State[0] = 0x67452301;        STATE[1] = 0xefcdab89;        STATE[2] = 0x98badcfe;        STATE[3] = 0x10325476; for (i = 0; i < digestbits.length; i++) Digestbits[i] = 0;        } function Update (b) {var index,i;        index = and (SHR (count[0],3), 0x3f);        if (count[0]<0xffffffff-7) count[0] + = 8;          else {count[1]++;          count[0]-=0xffffffff+1;        count[0]+=8;        } Buffer[index] = and (B,0XFF);        if (index >=) {transform (buffer, 0);        }} function Finish () {var bits = new Array (8);        var padding;        var i=0, index=0, padlen=0;        for (i = 0; i < 4; i++) {bits[i] = and (SHR (count[0), (i * 8)), 0xff);        } for (i = 0; i < 4; i++) {Bits[i+4]=and (SHR (count[1], (i * 8)), 0xff);        index = and (SHR (Count[0], 3), 0x3f); Padlen = (Index < 56)?        (56-index): (120-index);        padding = new Array (64);        Padding[0] = 0x80;        for (i=0;i<padlen;i++) update (padding[i]); for (i=0;i<8;i++) update (BITs[i]); for (i = 0; i < 4; i++) {for (j = 0; J < 4; J + +) {Digestbits[i*4+j] = and (SHR (state[i), (J * 8))            , 0xff); }}}/* Fin de l ' Algorithme MD5 */function hexa (n) {var hexa_h = "0123456789abcdef"; var hexa_c= ""; var hexa_m= N   for (hexa_i=0;hexa_i<8;hexa_i++) {Hexa_c=hexa_h.charat (Math.Abs (hexa_m)%16) +hexa_c; Hexa_m=math.floor (HEXA_M/16); } return hexa_c;} var ascii= "01234567890123456789012345678901" + "!\" #$%& ' () *+,-./0123456789:;<=>[email protected] " + "[\\]^_ ' abcdefghijklmnopqrstuvwxyz{|}   ~ "; function MD5 (message) {var l,s,k,ka,kb,kc,kd; init (); for (k=0;k<message.length;k++) {L=message.charat (k); Update (Ascii.lastindexof (l)); } finish (); Ka=kb=kc=kd=0; for (i=0;i<4;i++) KA+=SHL (Digestbits[15-i], (i*8)); for (i=4;i<8;i++) KB+=SHL (Digestbits[15-i], ((i-4) *8)); for (i=8;i<12;i++) KC+=SHL (Digestbits[15-i], ((i-8) *8)); for (i=12;i<16;i++) KD+=SHL (Digestbits[15-i], ((i-12) (*8)); S=hexa (KD) +hexa (KC) +hexa (KB) +hexa (KA); return s;}

Original address: http://blog.csdn.net/xiaozhi819/article/details/6901137

The "Go" JavaScript MD5 the same value as the Java messagedigest encryption

Related Article

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.