|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
×
2,escape()函数加密文本解密
- 有一种加密的办法是采用javascript的escape()函数,把某些符号、汉字等变成乱码,以达到迷惑人的目的。解密这种代码的办法是采用其反函数加以还原。下面是一个经过加密的例子:<BR>
- <font color=red>
- %3Chtml%3E%3Cbody%20bgcolor%3D%22white%22%3E%3Cp%3E%u8FD9%u662F%u4F8B%u5B50%uFF01%uFF01%uFF1A%uFF09%3C/p%3E%3C/body%3E%3C/html%3E</font><BR>
- 这种文件最好解密,一看就明白,关键是unescape()函数起了还原源代码的作用。要想看到加密前的代码是什么样子,可以用下面的办法(把红的字符复制到文本框中,然后解密就可以看到真相了):
- <SCRIPT LANGUAGE="Javascript">
- var Words ="%3Chtml%3E%3Cbody%20bgcolor%3D%22white%22%3E%3Cp%3E%u8FD9%u662F%u4F8B%u5B50%uFF01%uFF01%uFF1A%uFF09%3C/p%3E%3C/body%3E%3C/html%3E"
- var NewWords;
- NewWords = unescape(Words);
- NewWords=NewWords.toString();
- function password()&leftsign;
- document.pw.txtpw.value=NewWords;
- &rightsign;
- </SCRIPT>
- <form name=pw>
- <input type=button onclick="password()" value="解密">
- <br>
- <textarea name="txtpw" cols="80" rows="20"></textarea>
- </form>
复制代码
3,Ecode解码器 - <html>
- <head></head>
- <body>
- <script language="JScript">
- var STATE_COPY_INPUT = 100
- var STATE_READLEN = 101
- var STATE_DECODE = 102
- var STATE_UNESCAPE = 103
- var pick_encoding = new Array(
- 1, 2, 0, 1, 2, 0, 2, 0, 0, 2, 0, 2, 1, 0, 2, 0,
- 1, 0, 2, 0, 1, 1, 2, 0, 0, 2, 1, 0, 2, 0, 0, 2,
- 1, 1, 0, 2, 0, 2, 0, 1, 0, 1, 1, 2, 0, 1, 0, 2,
- 1, 0, 2, 0, 1, 1, 2, 0, 0, 1, 1, 2, 0, 1, 0, 2
- )
- var rawData = new Array(
- 0x64,0x37,0x69, 0x50,0x7E,0x2C, 0x22,0x5A,0x65, 0x4A,0x45,0x72,
- 0x61,0x3A,0x5B, 0x5E,0x79,0x66, 0x5D,0x59,0x75, 0x5B,0x27,0x4C,
- 0x42,0x76,0x45, 0x60,0x63,0x76, 0x23,0x62,0x2A, 0x65,0x4D,0x43,
- 0x5F,0x51,0x33, 0x7E,0x53,0x42, 0x4F,0x52,0x20, 0x52,0x20,0x63,
- 0x7A,0x26,0x4A, 0x21,0x54,0x5A, 0x46,0x71,0x38, 0x20,0x2B,0x79,
- 0x26,0x66,0x32, 0x63,0x2A,0x57, 0x2A,0x58,0x6C, 0x76,0x7F,0x2B,
- 0x47,0x7B,0x46, 0x25,0x30,0x52, 0x2C,0x31,0x4F, 0x29,0x6C,0x3D,
- 0x69,0x49,0x70, 0x3F,0x3F,0x3F, 0x27,0x78,0x7B, 0x3F,0x3F,0x3F,
- 0x67,0x5F,0x51, 0x3F,0x3F,0x3F, 0x62,0x29,0x7A, 0x41,0x24,0x7E,
- 0x5A,0x2F,0x3B, 0x66,0x39,0x47, 0x32,0x33,0x41, 0x73,0x6F,0x77,
- 0x4D,0x21,0x56, 0x43,0x75,0x5F, 0x71,0x28,0x26, 0x39,0x42,0x78,
- 0x7C,0x46,0x6E, 0x53,0x4A,0x64, 0x48,0x5C,0x74, 0x31,0x48,0x67,
- 0x72,0x36,0x7D, 0x6E,0x4B,0x68, 0x70,0x7D,0x35, 0x49,0x5D,0x22,
- 0x3F,0x6A,0x55, 0x4B,0x50,0x3A, 0x6A,0x69,0x60, 0x2E,0x23,0x6A,
- 0x7F,0x09,0x71, 0x28,0x70,0x6F, 0x35,0x65,0x49, 0x7D,0x74,0x5C,
- 0x24,0x2C,0x5D, 0x2D,0x77,0x27, 0x54,0x44,0x59, 0x37,0x3F,0x25,
- 0x7B,0x6D,0x7C, 0x3D,0x7C,0x23, 0x6C,0x43,0x6D, 0x34,0x38,0x28,
- 0x6D,0x5E,0x31, 0x4E,0x5B,0x39, 0x2B,0x6E,0x7F, 0x30,0x57,0x36,
- 0x6F,0x4C,0x54, 0x74,0x34,0x34, 0x6B,0x72,0x62, 0x4C,0x25,0x4E,
- 0x33,0x56,0x30, 0x56,0x73,0x5E, 0x3A,0x68,0x73, 0x78,0x55,0x09,
- 0x57,0x47,0x4B, 0x77,0x32,0x61, 0x3B,0x35,0x24, 0x44,0x2E,0x4D,
- 0x2F,0x64,0x6B, 0x59,0x4F,0x44, 0x45,0x3B,0x21, 0x5C,0x2D,0x37,
- 0x68,0x41,0x53, 0x36,0x61,0x58, 0x58,0x7A,0x48, 0x79,0x22,0x2E,
- 0x09,0x60,0x50, 0x75,0x6B,0x2D, 0x38,0x4E,0x29, 0x55,0x3D,0x3F
- )
- var transformed = new Array()
- for (var i=0; i<3; i++) transformed[i] = new Array()
- for (var i=31; i<=126; i++) for (var j=0; j<3; j++) transformed[j][rawData[(i-31) * 3 + j]] = (i==31) ? 9 : i
-
- var digits = new Array()
- for (var i=0; i<26; i++)
- &leftsign;
- digits["A".charCodeAt(0)+i] = i
- digits["a".charCodeAt(0)+i] = i+26
- &rightsign;
- for (var i=0; i<10; i++) digits["0".charCodeAt(0)+i] = i+52
- digits[0x2b] = 62
- digits[0x2f] = 63
- function unescape(char)
- &leftsign;
- var escapes = "#&!*$"
- var escaped = "\r\n<>@"
- if (char.charCodeAt(0) > 126) return char
- if (escapes.indexOf(char) != -1) return escaped.substr(escapes.indexOf(char), 1)
- return "?"
- &rightsign;
-
- function decodeBase64(string)
- &leftsign;
- var val = 0
- val += (digits[string.substr(0,1).charCodeAt(0)] << 2)
- val += (digits[string.substr(1,1).charCodeAt(0)] >> 4)
- val += (digits[string.substr(1,1).charCodeAt(0)] & 0xf) << 12
- val += ((digits[string.substr(2,1).charCodeAt(0)] >> 2) << 8)
- val += ((digits[string.substr(2,1).charCodeAt(0)] & 0x3) << 22)
- val += (digits[string.substr(3,1).charCodeAt(0)] << 16)
- return val
- &rightsign;
- function strdec(encodingString)
- &leftsign;
-
- var marker = "#@~^"
- var stringIndex = 0
- var scriptIndex = -1
- var unEncodingIndex = 0
- var char = null
- var encodingLength = unEncodinglength = 0
- var state = STATE_COPY_INPUT
- var unEncodingString = ""
- var re, arr
-
- while(state)
- &leftsign;
- switch (state)
- &leftsign;
- case (STATE_COPY_INPUT) :
- scriptIndex = encodingString.indexOf(marker, stringIndex)
- if (scriptIndex != -1)
- &leftsign;
- unEncodingString += encodingString.substring(stringIndex, scriptIndex)
- scriptIndex += marker.length
- state = STATE_READLEN
- &rightsign;
- else
- &leftsign;
- stringIndex = stringIndex==0 ? 0 : stringIndex
- unEncodingString += encodingString.substr(stringIndex, encodingString.length)
- state = 0
- &rightsign;
- break
-
- case (STATE_READLEN) :
- encodingLength = encodingString.substr(scriptIndex, 6)
- unEncodinglength = decodeBase64(encodingLength)
- scriptIndex += (6 + "==".length)
- state = STATE_DECODE
- break
-
- case (STATE_DECODE) :
- if (!unEncodinglength)
- &leftsign;
- stringIndex = scriptIndex + "DQgAAA==^#~@".length
- unEncodingIndex = 0
- state = STATE_COPY_INPUT
- break
- &rightsign;
- char = encodingString.substr(scriptIndex, 1)
- if (char == "@") state = STATE_UNESCAPE
- else
- &leftsign;
- if (char.charCodeAt(0) < 0xFF)
- &leftsign;
- unEncodingString += String.fromCharCode(transformed[pick_encoding[unEncodingIndex%64]][char.charCodeAt(0)])
- unEncodingIndex++
- &rightsign;
- else
- &leftsign;
- unEncodingString += char
- &rightsign;
- scriptIndex++
- unEncodinglength--
- break
- &rightsign;
-
- case STATE_UNESCAPE:
- unEncodingString += unescape(encodingString.substr(++scriptIndex, 1))
- scriptIndex++; unEncodinglength -=2
- unEncodingIndex++
- state = STATE_DECODE
- break
- &rightsign;
- &rightsign;
-
- re = new RegExp("(JScript&line;VBscript).encode", "gmi")
- while(arr = re.exec(unEncodingString)) unEncodingString = RegExp.leftContext + RegExp.$1 + RegExp.rightContext
- return unEncodingString
- &rightsign;
-
- </script>
- <textarea rows=10 cols=50 id=encodeHTML>
- <html>
- <head></head>
- <body>
- <script language="JScript.Encode">#@~^JAAAAA==@#@&b$;fAsM_qxFSt16n5IjP`.o啊噢e&rightsign;@#@&DQgAAA==^#~@</script>
- <script language="JScript.Encode">#@~^JAAAAA==@#@&b$;fAsM_qxFSt16n5IjP`.o啊噢e&rightsign;@#@&DQgAAA==^#~@</script>
- </body>
- </html>
- </textarea>
- <button onclick="encodeHTML.innerText=strdec(encodeHTML.innerText)">解密</botton>
- </body>
- </html>
复制代码
4.带密钥的加解密。
- <SCRIPT LANGUAGE="JavaScript">
- <!-- Begin
- function encrypt(str, pwd) &leftsign;
- if(pwd == null &line;&line; pwd.length <= 0) &leftsign;
- alert("Please enter a password with which to encrypt the message.");
- return null;
- &rightsign;
- var prand = "";
- for(var i=0; i<pwd.length; i++) &leftsign;
- prand += pwd.charCodeAt(i).toString();
- &rightsign;
- var sPos = Math.floor(prand.length / 5);
- var mult = parseInt(prand.charAt(sPos) + prand.charAt(sPos*2) + prand.charAt(sPos*3) + prand.charAt(sPos*4) + prand.charAt(sPos*5));
- var incr = Math.ceil(pwd.length / 2);
- var modu = Math.pow(2, 31) - 1;
- if(mult < 2) &leftsign;
- alert("Algorithm cannot find a suitable hash. Please choose a different password. \nPossible considerations are to choose a more complex or longer password.");
- return null;
- &rightsign;
- var salt = Math.round(Math.random() * 1000000000) % 100000000;
- prand += salt;
- while(prand.length > 10) &leftsign;
- prand = (parseInt(prand.substring(0, 10)) + parseInt(prand.substring(10, prand.length))).toString();
- &rightsign;
- prand = (mult * prand + incr) % modu;
- var enc_chr = "";
- var enc_str = "";
- for(var i=0; i<str.length; i++) &leftsign;
- enc_chr = parseInt(str.charCodeAt(i) ^ Math.floor((prand / modu) * 255));
- if(enc_chr < 16) &leftsign;
- enc_str += "0" + enc_chr.toString(16);
- &rightsign; else enc_str += enc_chr.toString(16);
- prand = (mult * prand + incr) % modu;
- &rightsign;
- salt = salt.toString(16);
- while(salt.length < 8)salt = "0" + salt;
- enc_str += salt;
- return enc_str;
- &rightsign;
- function decrypt(str, pwd) &leftsign;
- if(str == null &line;&line; str.length < 8) &leftsign;
- alert("A salt value could not be extracted from the encrypted message because it's length is too short. The message cannot be decrypted.");
- return;
- &rightsign;
- if(pwd == null &line;&line; pwd.length <= 0) &leftsign;
- alert("Please enter a password with which to decrypt the message.");
- return;
- &rightsign;
- var prand = "";
- for(var i=0; i<pwd.length; i++) &leftsign;
- prand += pwd.charCodeAt(i).toString();
- &rightsign;
- var sPos = Math.floor(prand.length / 5);
- var mult = parseInt(prand.charAt(sPos) + prand.charAt(sPos*2) + prand.charAt(sPos*3) + prand.charAt(sPos*4) + prand.charAt(sPos*5));
- var incr = Math.round(pwd.length / 2);
- var modu = Math.pow(2, 31) - 1;
- var salt = parseInt(str.substring(str.length - 8, str.length), 16);
- str = str.substring(0, str.length - 8);
- prand += salt;
- while(prand.length > 10) &leftsign;
- prand = (parseInt(prand.substring(0, 10)) + parseInt(prand.substring(10, prand.length))).toString();
- &rightsign;
- prand = (mult * prand + incr) % modu;
- var enc_chr = "";
- var enc_str = "";
- for(var i=0; i<str.length; i+=2) &leftsign;
- enc_chr = parseInt(parseInt(str.substring(i, i+2), 16) ^ Math.floor((prand / modu) * 255));
- enc_str += String.fromCharCode(enc_chr);
- prand = (mult * prand + incr) % modu;
- &rightsign;
- return enc_str;
- &rightsign;
- // End -->
- </script>
- <form name="box"><center>
- <table cellpadding=0 cellspacing=0 border=0><tr><td colspan=3>
- <textarea cols=40 rows=5 wrap=virtual name=ipt>Welcome to jzzy.com</textarea>
- </td></tr>
- <tr height=50><td valign="top">
- <input type="button" onclick="document.box.opt.value= encrypt(document.box.ipt.value, document.box.pwd.value);" value="加密">
- </td><td align="center" valign="center">
- <input type="text" name="pwd" value="password">
- </td><td align="right" valign="bottom">
- <input type="button" onclick="document.box.ipt.value= decrypt(document.box.opt.value, document.box.pwd.value);" value="解密">
- </td></tr>
- <tr><td colspan=3>
- <textarea cols=40 rows=5 wrap=virtual name=opt></textarea>
- </td></tr></table>
- </center>
- </form>
复制代码
5,Base64编码加密 - <script language=javascript>
- var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- var base64DecodeChars = new Array(
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
- 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
- -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
- -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
- 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);
- function base64encode(str) &leftsign;
- var out, i, len;
- var c1, c2, c3;
- len = str.length;
- i = 0;
- out = "";
- while(i < len) &leftsign;
- c1 = str.charCodeAt(i++) & 0xff;
- if(i == len)
- &leftsign;
- out += base64EncodeChars.charAt(c1 >> 2);
- out += base64EncodeChars.charAt((c1 & 0x3) << 4);
- out += "==";
- break;
- &rightsign;
- c2 = str.charCodeAt(i++);
- if(i == len)
- &leftsign;
- out += base64EncodeChars.charAt(c1 >> 2);
- out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) &line; ((c2 & 0xF0) >> 4));
- out += base64EncodeChars.charAt((c2 & 0xF) << 2);
- out += "=";
- break;
- &rightsign;
- c3 = str.charCodeAt(i++);
- out += base64EncodeChars.charAt(c1 >> 2);
- out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) &line; ((c2 & 0xF0) >> 4));
- out += base64EncodeChars.charAt(((c2 & 0xF) << 2) &line; ((c3 & 0xC0) >>6));
- out += base64EncodeChars.charAt(c3 & 0x3F);
- &rightsign;
- return out;
- &rightsign;
- function base64decode(str) &leftsign;
- var c1, c2, c3, c4;
- var i, len, out;
- len = str.length;
- i = 0;
- out = "";
- while(i < len) &leftsign;
- /* c1 */
- do &leftsign;
- c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
- &rightsign; while(i < len && c1 == -1);
- if(c1 == -1)
- break;
- /* c2 */
- do &leftsign;
- c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
- &rightsign; while(i < len && c2 == -1);
- if(c2 == -1)
- break;
- out += String.fromCharCode((c1 << 2) &line; ((c2 & 0x30) >> 4));
- /* c3 */
- do &leftsign;
- c3 = str.charCodeAt(i++) & 0xff;
- if(c3 == 61)
- return out;
- c3 = base64DecodeChars[c3];
- &rightsign; while(i < len && c3 == -1);
- if(c3 == -1)
- break;
- out += String.fromCharCode(((c2 & 0XF) << 4) &line; ((c3 & 0x3C) >> 2));
- /* c4 */
- do &leftsign;
- c4 = str.charCodeAt(i++) & 0xff;
- if(c4 == 61)
- return out;
- c4 = base64DecodeChars[c4];
- &rightsign; while(i < len && c4 == -1);
- if(c4 == -1)
- break;
- out += String.fromCharCode(((c3 & 0x03) << 6) &line; c4);
- &rightsign;
- return out;
- &rightsign;
- function utf16to8(str) &leftsign;
- var out, i, len, c;
- out = "";
- len = str.length;
- for(i = 0; i < len; i++) &leftsign;
- c = str.charCodeAt(i);
- if ((c >= 0x0001) && (c <= 0x007F)) &leftsign;
- out += str.charAt(i);
- &rightsign; else if (c > 0x07FF) &leftsign;
- out += String.fromCharCode(0xE0 &line; ((c >> 12) & 0x0F));
- out += String.fromCharCode(0x80 &line; ((c >> 6) & 0x3F));
- out += String.fromCharCode(0x80 &line; ((c >> 0) & 0x3F));
- &rightsign; else &leftsign;
- out += String.fromCharCode(0xC0 &line; ((c >> 6) & 0x1F));
- out += String.fromCharCode(0x80 &line; ((c >> 0) & 0x3F));
- &rightsign;
- &rightsign;
- return out;
- &rightsign;
- function utf8to16(str) &leftsign;
- var out, i, len, c;
- var char2, char3;
- out = "";
- len = str.length;
- i = 0;
- while(i < len) &leftsign;
- c = str.charCodeAt(i++);
- switch(c >> 4)
- &leftsign;
- case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
- // 0xxxxxxx
- out += str.charAt(i-1);
- break;
- case 12: case 13:
- // 110x xxxx 10xx xxxx
- char2 = str.charCodeAt(i++);
- out += String.fromCharCode(((c & 0x1F) << 6) &line; (char2 & 0x3F));
- break;
- case 14:
- // 1110 xxxx 10xx xxxx 10xx xxxx
- char2 = str.charCodeAt(i++);
- char3 = str.charCodeAt(i++);
- out += String.fromCharCode(((c & 0x0F) << 12) &line;
- ((char2 & 0x3F) << 6) &line;
- ((char3 & 0x3F) << 0));
- break;
- &rightsign;
- &rightsign;
- return out;
- &rightsign;
- function doit() &leftsign;
- var f = document.f
- f.output.value = base64encode(utf16to8(f.source.value))
- f.decode.value = utf8to16(base64decode(f.output.value))
- &rightsign;
- </script>
- <H1>Base64</H1>
- <FORM NAME="f">
- 原码<BR>
- <TEXTAREA NAME="source" ROWS=4 COLS=60 WRAP="soft"></TEXTAREA><BR><BR>
- Base64 encode<BR>
- <TEXTAREA NAME="output" ROWS=4 COLS=60 WRAP="soft"></TEXTAREA><BR><BR>
- Base64 decode<BR>
- <TEXTAREA NAME="decode" ROWS=4 COLS=60 WRAP="soft"></TEXTAREA><BR><BR>
- <INPUT TYPE=BUTTON VALUE="转换" ONCLICK="doit()">
- </FORM>
复制代码
6,md5的加密
- <input id=test value=sina>
- <input type=button value=md5 onclick="ye.value=hex_md5(test.value)">
- <p>
- <textarea style="font-family:fixedsys;font-size:12px;border:1px inset #d3d6d9" cols=40 rows=10 id=ye></textarea>
- <script>
- var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
- var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
- var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
- /*
- * These are the functions you'll usually want to call
- * They take string arguments and return either hex or base-64 encoded strings
- */
- function hex_md5(s)&leftsign; return binl2hex(core_md5(str2binl(s), s.length * chrsz));&rightsign;
- function b64_md5(s)&leftsign; return binl2b64(core_md5(str2binl(s), s.length * chrsz));&rightsign;
- function hex_hmac_md5(key, data) &leftsign; return binl2hex(core_hmac_md5(key, data)); &rightsign;
- function b64_hmac_md5(key, data) &leftsign; return binl2b64(core_hmac_md5(key, data)); &rightsign;
- /* Backwards compatibility - same as hex_md5() */
- function calcMD5(s)&leftsign; return binl2hex(core_md5(str2binl(s), s.length * chrsz));&rightsign;
- /*
- * Perform a simple self-test to see if the VM is working
- */
- function md5_vm_test()
- &leftsign;
- return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
- &rightsign;
- /*
- * Calculate the MD5 of an array of little-endian words, and a bit length
- */
- function core_md5(x, len)
- &leftsign;
- /* append padding */
- x[len >> 5] &line;= 0x80 << ((len) % 32);
- x[(((len + 64) >>> 9) << 4) + 14] = len;
-
- var a = 1732584193;
- var b = -271733879;
- var c = -1732584194;
- var d = 271733878;
- for(var i = 0; i < x.length; i += 16)
- &leftsign;
- var olda = a;
- 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, 606105819);
- 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, 1200080426);
- 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, 1236535329);
- 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, 643717713);
- 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, 1163531501);
- 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, 1735328473);
- 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, 1839030562);
- 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, 1272893353);
- 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, 76029189);
- 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, 530742520);
- 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, 1126891415);
- 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, 1309151649);
- 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, 718787259);
- 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);
- &rightsign;
- return Array(a, b, c, d);
-
- &rightsign;
- /*
- * These functions implement the four basic operations the algorithm uses.
- */
- function md5_cmn(q, a, b, x, s, t)
- &leftsign;
- return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
- &rightsign;
- function md5_ff(a, b, c, d, x, s, t)
- &leftsign;
- return md5_cmn((b & c) &line; ((~b) & d), a, b, x, s, t);
- &rightsign;
- function md5_gg(a, b, c, d, x, s, t)
- &leftsign;
- return md5_cmn((b & d) &line; (c & (~d)), a, b, x, s, t);
- &rightsign;
- function md5_hh(a, b, c, d, x, s, t)
- &leftsign;
- return md5_cmn(b ^ c ^ d, a, b, x, s, t);
- &rightsign;
- function md5_ii(a, b, c, d, x, s, t)
- &leftsign;
- return md5_cmn(c ^ (b &line; (~d)), a, b, x, s, t);
- &rightsign;
- /*
- * Calculate the HMAC-MD5, of a key and some data
- */
- function core_hmac_md5(key, data)
- &leftsign;
- var bkey = str2binl(key);
- if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);
- var ipad = Array(16), opad = Array(16);
- for(var i = 0; i < 16; i++)
- &leftsign;
- ipad[i] = bkey[i] ^ 0x36363636;
- opad[i] = bkey[i] ^ 0x5C5C5C5C;
- &rightsign;
- var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
- return core_md5(opad.concat(hash), 512 + 128);
- &rightsign;
- /*
- * Add integers, wrapping at 2^32. This uses 16-bit operations internally
- * to work around bugs in some JS interpreters.
- */
- function safe_add(x, y)
- &leftsign;
- var lsw = (x & 0xFFFF) + (y & 0xFFFF);
- var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
- return (msw << 16) &line; (lsw & 0xFFFF);
- &rightsign;
- /*
- * Bitwise rotate a 32-bit number to the left.
- */
- function bit_rol(num, cnt)
- &leftsign;
- return (num << cnt) &line; (num >>> (32 - cnt));
- &rightsign;
- /*
- * Convert a string to an array of little-endian words
- * If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
- */
- function str2binl(str)
- &leftsign;
- var bin = Array();
- var mask = (1 << chrsz) - 1;
- for(var i = 0; i < str.length * chrsz; i += chrsz)
- bin[i>>5] &line;= (str.charCodeAt(i / chrsz) & mask) << (i%32);
- return bin;
- &rightsign;
- /*
- * Convert an array of little-endian words to a hex string.
- */
- function binl2hex(binarray)
- &leftsign;
- var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
- var str = "";
- for(var i = 0; i < binarray.length * 4; i++)
- &leftsign;
- str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
- hex_tab.charAt((binarray[i>>2] >> ((i%4)*8 )) & 0xF);
- &rightsign;
- return str;
- &rightsign;
- /*
- * Convert an array of little-endian words to a base-64 string
- */
- function binl2b64(binarray)
- &leftsign;
- var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- var str = "";
- for(var i = 0; i < binarray.length * 4; i += 3)
- &leftsign;
- var triplet = (((binarray[i >> 2] >> 8 * ( i %4)) & 0xFF) << 16)
- &line; (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )
- &line; ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);
- for(var j = 0; j < 4; j++)
- &leftsign;
- if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
- else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
- &rightsign;
- &rightsign;
- return str;
- &rightsign;
- </script>
复制代码 |
|