/*****************************************************************************
* md5.js
*
* A JavaScript implementation of the RSA Data Security, Inc. MD5
* Message-Digest Algorithm.
*
* Copyright (C) Paul Johnston 1999. Distributed under the LGPL.
*****************************************************************************/
/* to convert strings to a list of ascii values */
var sAscii = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var sAscii = sAscii + "[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
/* convert integer to hex string */
var sHex = "0123456789ABCDEF";
function hex(i) {
h = "";
for(j = 0; j <= 3; j++) {
h += sHex.charAt((i >> (j * 8 + 4)) & 0x0F) +
sHex.charAt((i >> (j * 8)) & 0x0F);
}
return h;
}
/* add, handling overflows correctly */
function add(x, y) {
return ((x&0x7FFFFFFF) + (y&0x7FFFFFFF)) ^ (x&0x80000000) ^ (y&0x80000000);
}
/* MD5 rounds functions */
function R1(A, B, C, D, X, S, T) {
q = add(add(A, (B & C) | (~B & D)), add(X, T));
return add((q << S) | ((q >> (32 - S)) & (Math.pow(2, S) - 1)), B);
}
function R2(A, B, C, D, X, S, T) {
q = add(add(A, (B & D) | (C & ~D)), add(X, T));
return add((q << S) | ((q >> (32 - S)) & (Math.pow(2, S) - 1)), B);
}
function R3(A, B, C, D, X, S, T) {
q = add(add(A, B ^ C ^ D), add(X, T));
return add((q << S) | ((q >> (32 - S)) & (Math.pow(2, S) - 1)), B);
}
function R4(A, B, C, D, X, S, T) {
q = add(add(A, C ^ (B | ~D)), add(X, T));
return add((q << S) | ((q >> (32 - S)) & (Math.pow(2, S) - 1)), B);
}
/* main entry point */
function calcMD5(sInp) {
/* Calculate length in machine words, including padding */
JavaScriptÊÇÓÉNetscape¿ª·¢µÄ¹ã·ºÓÃÓÚÊý°ÙÍòÍøÒ³ºÍ·þÎñÆ÷Ó¦ÓóÌÐòµÄ¶ÔÏó½Å±¾ÓïÑÔ¡£NetscapeµÄJavaScriptÊÇECMA-262µÚÈý°æ(ECMAScript)±ê×¼½Å±¾ÓïÑÔµÄÒ»¸ö³¬¼¯£¬Ö»Óë·¢Ðбê×¼ÓÐЩÐí²»Í¬£¨mild differences£©¡£
Óë¹ã·ºµÄÎó½âÏà·´£¬JavaScript²»ÊÇ“½âÊÍÐ͵ÄJava”¡£×¼È·µÄ˵£¨In a nutshell£©£¬JavaScriptÊÇÖ§³Ö ......