MD5 encrypted JavaScript implementation

xiaoxiao2021-03-06  89

/ * 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 & 0x800000); LY8 = (Ly & 0x80000000); LX4 = (LX & 0x400000); LY4 = (LRESULT = (LX & 0x3ffffffff) (Ly & 0x3fffffff); if (LResult ^ 0x80000000 ^ LX8 ^ LY8); if (LX4 | LY4) {IF (LRESULT & 0X40000000) Return (LRESULT ^ 0xc0000000 ^ LX8 ^ LY8); Else Return (LRESULT ^ 0x400000 ^ lx8 ^ LY8);} else return (LRESULT ^ LX8 ^ ^;} 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 = AD Dunsigned (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 (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 >> 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 ( W ORDTOHEXVALUE_TEMP.LENGTH-2, 2);} Return WordtoHexValue;} var x = array (); var k, AA, BB, CC, DD, A, B, C, DVAR 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 wordsx = ConvertToWordArray (sMessage); // Step 3. Initialisea = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476; / / Step 4. Process the message in 16-word blocksfor (k = 0;

K

转载请注明原文地址:https://www.9cbs.com/read-122881.html

New Post(0)