MD5 32-bit FLASH Algorithm

Source: Internet
Author: User

//-----------
Function md5 (s ){
Return binl2hex (core_md5 (str2binl (s), s. length * strsize ));
}
Function core_md5 (x, len ){
X [len> 5] = (x [len> 5]) | (128 <len % 32 );
X [(len + 64) >>> 9) <4) + 14] = len;
Var a = 1732584193;
Var B =-271733879;
Var c =-1732584194;
Var d = 271733878;
Var I = 0;
While (I <x. length ){
Var olda =;
Var oldb = B;
Var oldc = c;
Var oldd = d;
A = md5_ff (a, B, c, d, x [I + 0], 7,-680876936 );
D = md5_ff (d, a, B, c, x [I + 1], 12,-389564586 );
C = md5_ff (c, d, a, B, x [I + 2], 17,606 105819 );
B = md5_ff (B, c, d, a, x [I + 3], 22,-1044525330 );
A = md5_ff (a, B, c, d, x [I + 4], 7,-176418897 );
D = md5_ff (d, a, B, c, x [I + 5], 12,120 0080426 );
C = md5_ff (c, d, a, B, x [I + 6], 17,- 1473231341 );
B = md5_ff (B, c, d, a, x [I + 7], 22,-45705983 );
A = md5_ff (a, B, c, d, x [I + 8], 7, 1770035416 );
D = md5_ff (d, a, B, c, x [I + 9], 12,-1958414417 );
C = md5_ff (c, d, a, B, x [I + 10], 17,- 42063 );
B = md5_ff (B, c, d, a, x [I + 11], 22,-1990404162 );
A = md5_ff (a, B, c, d, x [I + 12], 7, 1804603682 );
D = md5_ff (d, a, B, c, x [I + 13], 12,-40341101 );
C = md5_ff (c, d, a, B, x [I + 14], 17,- 1502002290 );
B = md5_ff (B, c, d, a, x [I + 15], 22,123 6521329 );
A = md5_gg (a, B, c, d, x [I + 1], 5,-165796510 );
D = md5_gg (d, a, B, c, x [I + 6], 9,-1069501632 );
C = md5_gg (c, d, a, B, x [I + 11], 14,643 717713 );
B = md5_gg (B, c, d, a, x [I + 0], 20,-373897302 );
A = md5_gg (a, B, c, d, x [I + 5], 5,-701558691 );
D = md5_gg (d, a, B, c, x [I + 10], 9, 38016083 );
C = md5_gg (c, d, a, B, x [I + 15], 14,-660478335 );
B = md5_gg (B, c, d, a, x [I + 4], 20,-405537848 );
A = md5_gg (a, B, c, d, x [I + 9], 5, 568446438 );
D = md5_gg (d, a, B, c, x [I + 14], 9,-1019803690 );
C = md5_gg (c, d, a, B, x [I + 3], 14,-187363961 );
B = md5_gg (B, c, d, a, x [I + 8], 20,116 limit 1501 );
A = md5_gg (a, B, c, d, x [I + 13], 5,-1444681467 );
D = md5_gg (d, a, B, c, x [I + 2], 9,-51403784 );
C = md5_gg (c, d, a, B, x [I + 7], 14,173 5328473 );
B = md5_gg (B, c, d, a, x [I + 12], 20,-1926607734 );
A = md5_hh (a, B, c, d, x [I + 5], 4,-378558 );
D = md5_hh (d, a, B, c, x [I + 8], 11,-2022574463 );
C = md5_hh (c, d, a, B, x [I + 11], 16,183 9030133 );
B = md5_hh (B, c, d, a, x [I + 14], 23,-35309556 );
A = md5_hh (a, B, c, d, x [I + 1], 4,-1530992060 );
D = md5_hh (d, a, B, c, x [I + 4], 11,127 2893353 );
C = md5_hh (c, d, a, B, x [I + 7], 16,-155497632 );
B = md5_hh (B, c, d, a, x [I + 10], 23,-1094730640 );
A = md5_hh (a, B, c, d, x [I + 13], 4, 681279174 );
D = md5_hh (d, a, B, c, x [I + 0], 11,-358537222 );
C = md5_hh (c, d, a, B, x [I + 3], 16,-722521979 );
B = md5_hh (B, c, d, a, x [I + 6], 23,760 29189 );
A = md5_hh (a, B, c, d, x [I + 9], 4,-640364487 );
D = md5_hh (d, a, B, c, x [I + 12], 11,-421815835 );
C = md5_hh (c, d, a, B, x [I + 15], 16,530 742520 );
B = md5_hh (B, c, d, a, x [I + 2], 23,-995338651 );
A = md5_ii (a, B, c, d, x [I + 0], 6,-198630844 );
D = md5_ii (d, a, B, c, x [I + 7], 10,112 6891415 );
C = md5_ii (c, d, a, B, x [I + 14], 15,-1416354905 );
B = md5_ii (B, c, d, a, x [I + 5], 21,-57434055 );
A = md5_ii (a, B, c, d, x [I + 12], 6, 1700485571 );
D = md5_ii (d, a, B, c, x [I + 3], 10,-1894986606 );
C = md5_ii (c, d, a, B, x [I + 10], 15,-1051523 );
B = md5_ii (B, c, d, a, x [I + 1], 21,-2054922799 );
A = md5_ii (a, B, c, d, x [I + 8], 6, 1873313359 );
D = md5_ii (d, a, B, c, x [I + 15], 10,-30611744 );
C = md5_ii (c, d, a, B, x [I + 6], 15,-1560198380 );
B = md5_ii (B, c, d, a, x [I + 13], 21,130 9151649 );
A = md5_ii (a, B, c, d, x [I + 4], 6,-145523070 );
D = md5_ii (d, a, B, c, x [I + 11], 10,-1120210379 );
C = md5_ii (c, d, a, B, x [I + 2], 15,718 787259 );
B = md5_ii (B, c, d, a, x [I + 9], 21,-343485551 );
A = safe_add (a, olda );
B = safe_add (B, oldb );
C = safe_add (c, oldc );
D = safe_add (d, oldd );
I = I + 16;
}
Return Array (a, B, c, d );
}
Function md5_cen (q, a, B, x, s, t ){
Return safe_add (bit_rol (safe_add (a, q), safe_add (x, t), s), B );
}
Function md5_ff (a, B, c, d, x, s, t ){
Return md5_cen (B & c) | ((~ B) & d), a, B, x, s, t );
}
Function md5_gg (a, B, c, d, x, s, t ){
Return md5_cen (B & d) | (c &(~ D), a, B, x, s, t );
}
Function md5_hh (a, B, c, d, x, s, t ){
Return md5_cen (B ^ c) ^ d, a, B, x, s, t );
}
Function md5_ii (a, B, c, d, x, s, t ){
Return md5_cen (c ^ (B | (~ D), a, B, x, s, t );
}
Function safe_add (x, y ){
Var lsw = (x & 65535) + (y & 65535 );
Var msw = (x> 16) + (y> 16) + (lsw> 16 );
Return (msw <16) | (lsw & 65535 );
}
Function bit_rol (num, cnt ){
Return (num <cnt) | (num >>> (32-cnt ));
}
Function str2binl (str ){
Var bin = Array ();
Var mask = (1 <strsize)-1;
Var I = 0;
While (I <(str. length * strsize )){
Bin [I> 5] = (bin [I> 5]) | (str. charCodeAt (I/strsize) & mask) <I % 32 );
I = I + strsize;
}
Return bin;
}
Function binl2hex (binarray ){
If (hexcase ){
} Else {
}
Var hex_tab = "0123456789 abcdef ";
Var str = "";
Var I = 0;
While (I <(binarray. length * 4 )){
Str = str + (hex_tab.charAt (binarray [I> 2]) >>( (I % 4*8) + 4) & 15) + hex_tab.charAt (binarray [I> 2])> (I % 4*8) & 15 ));
I ++;
}
Return str;
}
Var hexcase = 0;
Var strsize = 8;
// -------- Do not modify the above,
B = md5 ("xx ");
// Xx can be set to any character
S = B. toUpperCase ();
// Convert to uppercase
Trace (B );
Trace (s );

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.