找回密码
 注册
【阿里云】2核2G云新老同享 99元/年,续费同价华为云精选云产品特惠做网站就用糖果主机Jtti,新加坡服务器,美国服务器,香港服务器
查看: 861|回复: 20

HTML原代码加、解密脚本

[复制链接]
发表于 2005 年 2 月 11 日 21:07:25 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

×
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  4. <title>It365cn.com</title>
  5. <style type="text/css">
  6. <!--
  7. .coolalpha &leftsign;behavior:url(eyun_alpha.htc);cursor:hand;filter:alpha(opacity=50);&rightsign;
  8. -->
  9. </style>
  10. </head>
  11. <body leftmargin="0" topmargin="0">
  12. <SCRIPT language=JavaScript><!--
  13. var i=0;
  14. var ie=(document.all)?1:0;
  15. var ns=(document.layers)?1:0;
  16. function initStyleElements() /* Styles for Buttons Init */
  17. &leftsign;
  18. var c = document.pad;
  19. if (ie)
  20. &leftsign;
  21. //c.text.style.backgroundColor="#DDDDDD";
  22. c.compileIt.style.backgroundColor="#C0C0A8";
  23. c.compileIt.style.cursor="hand";
  24. c.select.style.backgroundColor="#C0C0A8";
  25. c.select.style.cursor="hand";
  26. c.view.style.backgroundColor="#C0C0A8";
  27. c.view.style.cursor="hand";
  28. c.retur.style.backgroundColor="#C0C0A8";
  29. c.retur.style.cursor="hand";
  30. c.clear.style.backgroundColor="#C0C0A8";
  31. c.clear.style.cursor="hand";
  32. &rightsign;
  33. else return;
  34. &rightsign;
  35. /* Buttons Enlightment of "Compilation" panel */
  36. function FocusOn(what)
  37. &leftsign;
  38. if (ie) what.style.backgroundColor = '#EBEBEB';
  39. else return;
  40. &rightsign;
  41. function FocusOff(what)
  42. &leftsign;
  43. if (ie) what.style.backgroundColor = '#DDDDDD';
  44. else return;
  45. &rightsign;
  46. /* Buttons Enlightment of "Compilation" panel */
  47. function generate() /* Generation of "Compilation" */
  48. &leftsign;
  49. code = document.pad.text.value;
  50. if (code)
  51. &leftsign;
  52. document.pad.text.value='Compiling...Please wait!';
  53. setTimeout("compile()",1000);
  54. &rightsign;
  55. else alert('First enter something to compile and then press CompileIt')
  56. &rightsign;
  57. function compile() /* The "Compilation" */
  58. &leftsign;
  59. document.pad.text.value='';
  60. compilation=escape(code);
  61. document.pad.text.value="<script>\n<!--\ndocument.write(unescape(\""+compilation+"\"));\n//-->\n<\/script>";
  62. i++;
  63. if (i=1) alert("Page compiled 1 time!");
  64. else alert("Page compiled "+i+" times!");
  65. &rightsign;
  66. function selectCode() /* Selecting "Compilation" for Copying */
  67. &leftsign;
  68. if(document.pad.text.value.length>0)
  69. &leftsign;
  70. document.pad.text.focus();
  71. document.pad.text.select();
  72. &rightsign;
  73. else alert('Nothing for be selected!')
  74. &rightsign;
  75. function preview() /* Preview for the "Compilation" */
  76. &leftsign;
  77. if(document.pad.text.value.length>0)
  78. &leftsign;
  79. pr=window.open("","Preview","scrollbars=1,menubar=1,status=1,width=700,height=320,left=50,top=110");
  80. pr.document.write(document.pad.text.value);
  81. &rightsign;
  82. else alert('Nothing for be previewed!')
  83. &rightsign;
  84. function uncompile() /* Decompiling a "Compilation" */
  85. &leftsign;
  86. if (document.pad.text.value.length>0)
  87. &leftsign;
  88. source=unescape(document.pad.text.value);
  89. document.pad.text.value=""+source+"";
  90. &rightsign;
  91. else alert('You need compiled code to uncompile it!')
  92. &rightsign;
  93. // -->
  94. </SCRIPT>
  95. <table width="650" border="0" cellpadding="0" cellspacing="0">
  96.   <tr>
  97.    <td bgcolor="#3568AC"></td>
  98.    <td width="87" height="1"></td>
  99.    <td width="460" height="1" bgcolor="#3568AC"></td>
  100.    <td width="100" height="1"></td>
  101.    <td bgcolor="#3568AC"></td>
  102.   </tr>
  103.   <tr>
  104.    <td bgcolor="#3568AC" height="6"></td>
  105.    <td height="8" colspan="3" class="cn"></td>
  106.    <td bgcolor="#3568AC" height="6"></td>
  107.   </tr>
  108.   <tr>
  109.    <td bgcolor="#3568AC"></td>
  110.    <td height="296" colspan="3" align="center" class="gp">
  111. <FORM name=pad method=post align="center">
  112. <TEXTAREA name=text rows=11 cols=50></TEXTAREA>
  113. <BR><BR>
  114. <INPUT  onclick=generate()  type=button value=加密 name=compileIt>
  115. <INPUT  onclick=selectCode()  type=button value=全选 name=select>
  116. <INPUT  onclick=preview()  type=button value=预览 name=view>
  117. <INPUT  onclick=uncompile()  type=button value=解密 name=retur>
  118. <INPUT   type=reset value=清除 name=clear></FORM>    
  119.    </td>
  120.    <td bgcolor="#3568AC"></td>
  121.   </tr>
  122.   <tr>
  123.    <td bgcolor="#3568AC" height="6"></td>
  124.    <td height="8" colspan="3" class="cn"></td>
  125.    <td bgcolor="#3568AC" height="6"></td>
  126.   </tr>
  127.   <tr>
  128.    <td bgcolor="#3568AC"></td>
  129.    <td colspan="3" align="center"> <input type="button" name="Submit2" value="关闭窗口" onclick="window.close()" style="cursor:hand"
  130. onFocus="if(this.blur)this.blur()">
  131.    </td>
  132.    <td bgcolor="#3568AC"></td>
  133.   </tr>
  134.   <tr>
  135.    <td bgcolor="#3568AC" height="6"></td>
  136.    <td height="8" colspan="3" class="cn"></td>
  137.    <td bgcolor="#3568AC" height="6"></td>
  138.   </tr>
  139. </table>
  140. </body>
  141. </html>
复制代码

2,escape()函数加密文本解密
  1. 有一种加密的办法是采用javascript的escape()函数,把某些符号、汉字等变成乱码,以达到迷惑人的目的。解密这种代码的办法是采用其反函数加以还原。下面是一个经过加密的例子:<BR>
  2. <font color=red>
  3. %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>
  4.   这种文件最好解密,一看就明白,关键是unescape()函数起了还原源代码的作用。要想看到加密前的代码是什么样子,可以用下面的办法(把红的字符复制到文本框中,然后解密就可以看到真相了):
  5. <SCRIPT LANGUAGE="Javascript">
  6. 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"
  7. var NewWords;
  8. NewWords = unescape(Words);
  9. NewWords=NewWords.toString();
  10. function password()&leftsign;
  11. document.pw.txtpw.value=NewWords;
  12. &rightsign;
  13. </SCRIPT>
  14. <form name=pw>
  15. <input type=button onclick="password()" value="解密">
  16. <br>
  17. <textarea name="txtpw" cols="80" rows="20"></textarea>
  18. </form>
复制代码



3,Ecode解码器
  1. <html>
  2. <head></head>
  3. <body>
  4. <script language="JScript">
  5.    var STATE_COPY_INPUT        = 100
  6.    var STATE_READLEN        = 101
  7.    var STATE_DECODE        = 102
  8.    var STATE_UNESCAPE        = 103
  9.    var pick_encoding = new Array(
  10.        1, 2, 0, 1, 2, 0, 2, 0, 0, 2, 0, 2, 1, 0, 2, 0,
  11.        1, 0, 2, 0, 1, 1, 2, 0, 0, 2, 1, 0, 2, 0, 0, 2,
  12.        1, 1, 0, 2, 0, 2, 0, 1, 0, 1, 1, 2, 0, 1, 0, 2,
  13.        1, 0, 2, 0, 1, 1, 2, 0, 0, 1, 1, 2, 0, 1, 0, 2
  14.    )
  15.    var rawData = new Array(
  16.        0x64,0x37,0x69, 0x50,0x7E,0x2C, 0x22,0x5A,0x65, 0x4A,0x45,0x72,
  17.        0x61,0x3A,0x5B, 0x5E,0x79,0x66, 0x5D,0x59,0x75, 0x5B,0x27,0x4C,
  18.        0x42,0x76,0x45, 0x60,0x63,0x76, 0x23,0x62,0x2A, 0x65,0x4D,0x43,
  19.        0x5F,0x51,0x33, 0x7E,0x53,0x42, 0x4F,0x52,0x20, 0x52,0x20,0x63,
  20.        0x7A,0x26,0x4A, 0x21,0x54,0x5A, 0x46,0x71,0x38, 0x20,0x2B,0x79,
  21.        0x26,0x66,0x32, 0x63,0x2A,0x57, 0x2A,0x58,0x6C, 0x76,0x7F,0x2B,
  22.        0x47,0x7B,0x46, 0x25,0x30,0x52, 0x2C,0x31,0x4F, 0x29,0x6C,0x3D,
  23.        0x69,0x49,0x70, 0x3F,0x3F,0x3F, 0x27,0x78,0x7B, 0x3F,0x3F,0x3F,
  24.        0x67,0x5F,0x51, 0x3F,0x3F,0x3F, 0x62,0x29,0x7A, 0x41,0x24,0x7E,
  25.        0x5A,0x2F,0x3B, 0x66,0x39,0x47, 0x32,0x33,0x41, 0x73,0x6F,0x77,
  26.        0x4D,0x21,0x56, 0x43,0x75,0x5F, 0x71,0x28,0x26, 0x39,0x42,0x78,
  27.        0x7C,0x46,0x6E, 0x53,0x4A,0x64, 0x48,0x5C,0x74, 0x31,0x48,0x67,
  28.        0x72,0x36,0x7D, 0x6E,0x4B,0x68, 0x70,0x7D,0x35, 0x49,0x5D,0x22,
  29.        0x3F,0x6A,0x55, 0x4B,0x50,0x3A, 0x6A,0x69,0x60, 0x2E,0x23,0x6A,
  30.        0x7F,0x09,0x71, 0x28,0x70,0x6F, 0x35,0x65,0x49, 0x7D,0x74,0x5C,
  31.        0x24,0x2C,0x5D, 0x2D,0x77,0x27, 0x54,0x44,0x59, 0x37,0x3F,0x25,
  32.        0x7B,0x6D,0x7C, 0x3D,0x7C,0x23, 0x6C,0x43,0x6D, 0x34,0x38,0x28,
  33.        0x6D,0x5E,0x31, 0x4E,0x5B,0x39, 0x2B,0x6E,0x7F, 0x30,0x57,0x36,
  34.        0x6F,0x4C,0x54, 0x74,0x34,0x34, 0x6B,0x72,0x62, 0x4C,0x25,0x4E,
  35.        0x33,0x56,0x30, 0x56,0x73,0x5E, 0x3A,0x68,0x73, 0x78,0x55,0x09,
  36.        0x57,0x47,0x4B, 0x77,0x32,0x61, 0x3B,0x35,0x24, 0x44,0x2E,0x4D,
  37.        0x2F,0x64,0x6B, 0x59,0x4F,0x44, 0x45,0x3B,0x21, 0x5C,0x2D,0x37,
  38.        0x68,0x41,0x53, 0x36,0x61,0x58, 0x58,0x7A,0x48, 0x79,0x22,0x2E,
  39.        0x09,0x60,0x50, 0x75,0x6B,0x2D, 0x38,0x4E,0x29, 0x55,0x3D,0x3F
  40.    )
  41.    var transformed = new Array()
  42.    for (var i=0; i<3; i++)    transformed[i] = new Array()
  43.    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
  44.    
  45.    var digits = new Array()
  46.    for (var i=0; i<26; i++)
  47.    &leftsign;
  48.        digits["A".charCodeAt(0)+i] = i
  49.        digits["a".charCodeAt(0)+i] = i+26
  50.    &rightsign;
  51.    for (var i=0; i<10; i++)    digits["0".charCodeAt(0)+i] = i+52
  52.    digits[0x2b] = 62
  53.    digits[0x2f] = 63
  54.    function unescape(char)
  55.    &leftsign;
  56.        var escapes = "#&!*$"
  57.        var escaped = "\r\n<>@"
  58.        if (char.charCodeAt(0) > 126)    return char
  59.        if (escapes.indexOf(char) != -1)    return escaped.substr(escapes.indexOf(char), 1)
  60.        return "?"
  61.    &rightsign;
  62.    
  63.    function decodeBase64(string)
  64.    &leftsign;
  65.        var val = 0
  66.        val +=  (digits[string.substr(0,1).charCodeAt(0)] << 2)
  67.        val +=  (digits[string.substr(1,1).charCodeAt(0)] >> 4)
  68.        val +=  (digits[string.substr(1,1).charCodeAt(0)] & 0xf) << 12
  69.        val += ((digits[string.substr(2,1).charCodeAt(0)] >> 2) << 8)
  70.        val += ((digits[string.substr(2,1).charCodeAt(0)] & 0x3) << 22)
  71.        val +=  (digits[string.substr(3,1).charCodeAt(0)] << 16)
  72.        return val
  73.    &rightsign;
  74.    function strdec(encodingString)
  75.    &leftsign;
  76.        
  77.        var marker = "#@~^"
  78.        var stringIndex = 0
  79.        var scriptIndex = -1
  80.        var unEncodingIndex = 0
  81.        var char = null
  82.        var encodingLength = unEncodinglength = 0
  83.        var state = STATE_COPY_INPUT
  84.        var unEncodingString = ""
  85.        var re, arr
  86.        
  87.        while(state)
  88.        &leftsign;
  89.            switch (state)
  90.            &leftsign;
  91.                case (STATE_COPY_INPUT)    :
  92.                    scriptIndex = encodingString.indexOf(marker, stringIndex)
  93.                    if (scriptIndex != -1)
  94.                    &leftsign;
  95.                        unEncodingString += encodingString.substring(stringIndex, scriptIndex)
  96.                        scriptIndex += marker.length
  97.                        state = STATE_READLEN
  98.                    &rightsign;
  99.                    else
  100.                    &leftsign;
  101.                        stringIndex = stringIndex==0 ? 0 : stringIndex
  102.                        unEncodingString += encodingString.substr(stringIndex, encodingString.length)
  103.                        state = 0
  104.                    &rightsign;
  105.                    break
  106.                
  107.                case (STATE_READLEN)    :
  108.                    encodingLength = encodingString.substr(scriptIndex, 6)
  109.                    unEncodinglength = decodeBase64(encodingLength)
  110.                    scriptIndex += (6 + "==".length)
  111.                    state = STATE_DECODE
  112.                    break
  113.                    
  114.                case (STATE_DECODE)    :
  115.                    if (!unEncodinglength)
  116.                    &leftsign;
  117.                        stringIndex = scriptIndex + "DQgAAA==^#~@".length
  118.                        unEncodingIndex = 0
  119.                        state = STATE_COPY_INPUT
  120.                        break
  121.                    &rightsign;
  122.                    char = encodingString.substr(scriptIndex, 1)
  123.                    if (char == "@")    state = STATE_UNESCAPE
  124.                    else
  125.                    &leftsign;
  126.                        if (char.charCodeAt(0) < 0xFF)
  127.                        &leftsign;
  128.                            unEncodingString += String.fromCharCode(transformed[pick_encoding[unEncodingIndex%64]][char.charCodeAt(0)])
  129.                            unEncodingIndex++
  130.                        &rightsign;
  131.                        else
  132.                        &leftsign;
  133.                            unEncodingString += char
  134.                        &rightsign;                       
  135.                        scriptIndex++
  136.                        unEncodinglength--
  137.                        break
  138.                    &rightsign;
  139.                    
  140.                case STATE_UNESCAPE:
  141.                    unEncodingString += unescape(encodingString.substr(++scriptIndex, 1))
  142.                    scriptIndex++;    unEncodinglength -=2
  143.                    unEncodingIndex++
  144.                    state = STATE_DECODE
  145.                    break
  146.            &rightsign;
  147.        &rightsign;
  148.        
  149.        re  = new RegExp("(JScript&line;VBscript).encode", "gmi")
  150.        while(arr = re.exec(unEncodingString))    unEncodingString = RegExp.leftContext + RegExp.$1 + RegExp.rightContext
  151.        return unEncodingString
  152.    &rightsign;
  153.    
  154. </script>
  155. <textarea rows=10 cols=50 id=encodeHTML>
  156. <html>
  157. <head></head>
  158. <body>
  159. <script language="JScript.Encode">#@~^JAAAAA==@#@&b$;fAsM_qxFSt16n5IjP`.o啊噢e&rightsign;@#@&DQgAAA==^#~@</script>
  160. <script language="JScript.Encode">#@~^JAAAAA==@#@&b$;fAsM_qxFSt16n5IjP`.o啊噢e&rightsign;@#@&DQgAAA==^#~@</script>
  161. </body>
  162. </html>
  163. </textarea>
  164. <button onclick="encodeHTML.innerText=strdec(encodeHTML.innerText)">解密</botton>
  165. </body>
  166. </html>
复制代码


4.带密钥的加解密。



  1. <SCRIPT LANGUAGE="JavaScript">
  2. <!-- Begin
  3. function encrypt(str, pwd) &leftsign;
  4.   if(pwd == null &line;&line; pwd.length <= 0) &leftsign;
  5.    alert("Please enter a password with which to encrypt the message.");
  6.    return null;
  7.   &rightsign;
  8.   var prand = "";
  9.   for(var i=0; i<pwd.length; i++) &leftsign;
  10.    prand += pwd.charCodeAt(i).toString();
  11.   &rightsign;
  12.   var sPos = Math.floor(prand.length / 5);
  13.   var mult = parseInt(prand.charAt(sPos) + prand.charAt(sPos*2) + prand.charAt(sPos*3) + prand.charAt(sPos*4) + prand.charAt(sPos*5));
  14.   var incr = Math.ceil(pwd.length / 2);
  15.   var modu = Math.pow(2, 31) - 1;
  16.   if(mult < 2) &leftsign;
  17.    alert("Algorithm cannot find a suitable hash. Please choose a different password. \nPossible considerations are to choose a more complex or longer password.");
  18.    return null;
  19.   &rightsign;
  20.   var salt = Math.round(Math.random() * 1000000000) % 100000000;
  21.   prand += salt;
  22.   while(prand.length > 10) &leftsign;
  23.    prand = (parseInt(prand.substring(0, 10)) + parseInt(prand.substring(10, prand.length))).toString();
  24.   &rightsign;
  25.   prand = (mult * prand + incr) % modu;
  26.   var enc_chr = "";
  27.   var enc_str = "";
  28.   for(var i=0; i<str.length; i++) &leftsign;
  29.    enc_chr = parseInt(str.charCodeAt(i) ^ Math.floor((prand / modu) * 255));
  30.    if(enc_chr < 16) &leftsign;
  31.      enc_str += "0" + enc_chr.toString(16);
  32.    &rightsign; else enc_str += enc_chr.toString(16);
  33.    prand = (mult * prand + incr) % modu;
  34.   &rightsign;
  35.   salt = salt.toString(16);
  36.   while(salt.length < 8)salt = "0" + salt;
  37.   enc_str += salt;
  38.   return enc_str;
  39. &rightsign;
  40. function decrypt(str, pwd) &leftsign;
  41.   if(str == null &line;&line; str.length < 8) &leftsign;
  42.    alert("A salt value could not be extracted from the encrypted message because it's length is too short. The message cannot be decrypted.");
  43.    return;
  44.   &rightsign;
  45.   if(pwd == null &line;&line; pwd.length <= 0) &leftsign;
  46.    alert("Please enter a password with which to decrypt the message.");
  47.    return;
  48.   &rightsign;
  49.   var prand = "";
  50.   for(var i=0; i<pwd.length; i++) &leftsign;
  51.    prand += pwd.charCodeAt(i).toString();
  52.   &rightsign;
  53.   var sPos = Math.floor(prand.length / 5);
  54.   var mult = parseInt(prand.charAt(sPos) + prand.charAt(sPos*2) + prand.charAt(sPos*3) + prand.charAt(sPos*4) + prand.charAt(sPos*5));
  55.   var incr = Math.round(pwd.length / 2);
  56.   var modu = Math.pow(2, 31) - 1;
  57.   var salt = parseInt(str.substring(str.length - 8, str.length), 16);
  58.   str = str.substring(0, str.length - 8);
  59.   prand += salt;
  60.   while(prand.length > 10) &leftsign;
  61.    prand = (parseInt(prand.substring(0, 10)) + parseInt(prand.substring(10, prand.length))).toString();
  62.   &rightsign;
  63.   prand = (mult * prand + incr) % modu;
  64.   var enc_chr = "";
  65.   var enc_str = "";
  66.   for(var i=0; i<str.length; i+=2) &leftsign;
  67.    enc_chr = parseInt(parseInt(str.substring(i, i+2), 16) ^ Math.floor((prand / modu) * 255));
  68.    enc_str += String.fromCharCode(enc_chr);
  69.    prand = (mult * prand + incr) % modu;
  70.   &rightsign;
  71.   return enc_str;
  72. &rightsign;
  73. //  End -->
  74. </script>
  75. <form name="box"><center>
  76. <table cellpadding=0 cellspacing=0 border=0><tr><td colspan=3>
  77. <textarea cols=40 rows=5 wrap=virtual name=ipt>Welcome to jzzy.com</textarea>
  78. </td></tr>
  79. <tr height=50><td valign="top">
  80. <input type="button" onclick="document.box.opt.value= encrypt(document.box.ipt.value, document.box.pwd.value);" value="加密">
  81. </td><td align="center" valign="center">
  82. <input type="text" name="pwd" value="password">
  83. </td><td align="right" valign="bottom">
  84. <input type="button" onclick="document.box.ipt.value= decrypt(document.box.opt.value, document.box.pwd.value);" value="解密">
  85. </td></tr>
  86. <tr><td colspan=3>
  87. <textarea cols=40 rows=5 wrap=virtual name=opt></textarea>
  88. </td></tr></table>
  89. </center>
  90. </form>
复制代码

5,Base64编码加密
  1. <script language=javascript>
  2. var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  3. var base64DecodeChars = new Array(
  4.    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  5.    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  6.    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
  7.    52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
  8.    -1,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
  9.    15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
  10.    -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
  11.    41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);
  12. function base64encode(str) &leftsign;
  13.    var out, i, len;
  14.    var c1, c2, c3;
  15.    len = str.length;
  16.    i = 0;
  17.    out = "";
  18.    while(i < len) &leftsign;
  19.    c1 = str.charCodeAt(i++) & 0xff;
  20.    if(i == len)
  21.    &leftsign;
  22.        out += base64EncodeChars.charAt(c1 >> 2);
  23.        out += base64EncodeChars.charAt((c1 & 0x3) << 4);
  24.        out += "==";
  25.        break;
  26.    &rightsign;
  27.    c2 = str.charCodeAt(i++);
  28.    if(i == len)
  29.    &leftsign;
  30.        out += base64EncodeChars.charAt(c1 >> 2);
  31.        out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) &line; ((c2 & 0xF0) >> 4));
  32.        out += base64EncodeChars.charAt((c2 & 0xF) << 2);
  33.        out += "=";
  34.        break;
  35.    &rightsign;
  36.    c3 = str.charCodeAt(i++);
  37.    out += base64EncodeChars.charAt(c1 >> 2);
  38.    out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) &line; ((c2 & 0xF0) >> 4));
  39.    out += base64EncodeChars.charAt(((c2 & 0xF) << 2) &line; ((c3 & 0xC0) >>6));
  40.    out += base64EncodeChars.charAt(c3 & 0x3F);
  41.    &rightsign;
  42.    return out;
  43. &rightsign;
  44. function base64decode(str) &leftsign;
  45.    var c1, c2, c3, c4;
  46.    var i, len, out;
  47.    len = str.length;
  48.    i = 0;
  49.    out = "";
  50.    while(i < len) &leftsign;
  51.    /* c1 */
  52.    do &leftsign;
  53.        c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
  54.    &rightsign; while(i < len && c1 == -1);
  55.    if(c1 == -1)
  56.        break;
  57.    /* c2 */
  58.    do &leftsign;
  59.        c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
  60.    &rightsign; while(i < len && c2 == -1);
  61.    if(c2 == -1)
  62.        break;
  63.    out += String.fromCharCode((c1 << 2) &line; ((c2 & 0x30) >> 4));
  64.    /* c3 */
  65.    do &leftsign;
  66.        c3 = str.charCodeAt(i++) & 0xff;
  67.        if(c3 == 61)
  68.        return out;
  69.        c3 = base64DecodeChars[c3];
  70.    &rightsign; while(i < len && c3 == -1);
  71.    if(c3 == -1)
  72.        break;
  73.    out += String.fromCharCode(((c2 & 0XF) << 4) &line; ((c3 & 0x3C) >> 2));
  74.    /* c4 */
  75.    do &leftsign;
  76.        c4 = str.charCodeAt(i++) & 0xff;
  77.        if(c4 == 61)
  78.        return out;
  79.        c4 = base64DecodeChars[c4];
  80.    &rightsign; while(i < len && c4 == -1);
  81.    if(c4 == -1)
  82.        break;
  83.    out += String.fromCharCode(((c3 & 0x03) << 6) &line; c4);
  84.    &rightsign;
  85.    return out;
  86. &rightsign;
  87. function utf16to8(str) &leftsign;
  88.    var out, i, len, c;
  89.    out = "";
  90.    len = str.length;
  91.    for(i = 0; i < len; i++) &leftsign;
  92.    c = str.charCodeAt(i);
  93.    if ((c >= 0x0001) && (c <= 0x007F)) &leftsign;
  94.        out += str.charAt(i);
  95.    &rightsign; else if (c > 0x07FF) &leftsign;
  96.        out += String.fromCharCode(0xE0 &line; ((c >> 12) & 0x0F));
  97.        out += String.fromCharCode(0x80 &line; ((c >>  6) & 0x3F));
  98.        out += String.fromCharCode(0x80 &line; ((c >>  0) & 0x3F));
  99.    &rightsign; else &leftsign;
  100.        out += String.fromCharCode(0xC0 &line; ((c >>  6) & 0x1F));
  101.        out += String.fromCharCode(0x80 &line; ((c >>  0) & 0x3F));
  102.    &rightsign;
  103.    &rightsign;
  104.    return out;
  105. &rightsign;
  106. function utf8to16(str) &leftsign;
  107.    var out, i, len, c;
  108.    var char2, char3;
  109.    out = "";
  110.    len = str.length;
  111.    i = 0;
  112.    while(i < len) &leftsign;
  113.    c = str.charCodeAt(i++);
  114.    switch(c >> 4)
  115.    &leftsign;
  116.      case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
  117.        // 0xxxxxxx
  118.        out += str.charAt(i-1);
  119.        break;
  120.      case 12: case 13:
  121.        // 110x xxxx   10xx xxxx
  122.        char2 = str.charCodeAt(i++);
  123.        out += String.fromCharCode(((c & 0x1F) << 6) &line; (char2 & 0x3F));
  124.        break;
  125.      case 14:
  126.        // 1110 xxxx  10xx xxxx  10xx xxxx
  127.        char2 = str.charCodeAt(i++);
  128.        char3 = str.charCodeAt(i++);
  129.        out += String.fromCharCode(((c & 0x0F) << 12) &line;
  130.                       ((char2 & 0x3F) << 6) &line;
  131.                       ((char3 & 0x3F) << 0));
  132.        break;
  133.    &rightsign;
  134.    &rightsign;
  135.    return out;
  136. &rightsign;
  137. function doit() &leftsign;
  138.    var f = document.f
  139.    f.output.value = base64encode(utf16to8(f.source.value))
  140.    f.decode.value = utf8to16(base64decode(f.output.value))
  141. &rightsign;
  142. </script>
  143. <H1>Base64</H1>
  144. <FORM NAME="f">
  145. 原码<BR>
  146. <TEXTAREA NAME="source" ROWS=4 COLS=60 WRAP="soft"></TEXTAREA><BR><BR>
  147. Base64 encode<BR>
  148. <TEXTAREA NAME="output" ROWS=4 COLS=60 WRAP="soft"></TEXTAREA><BR><BR>
  149. Base64 decode<BR>
  150. <TEXTAREA NAME="decode" ROWS=4 COLS=60 WRAP="soft"></TEXTAREA><BR><BR>
  151. <INPUT TYPE=BUTTON VALUE="转换" ONCLICK="doit()">
  152. </FORM>
复制代码


6,md5的加密
  1. <input id=test value=sina>
  2. <input type=button value=md5 onclick="ye.value=hex_md5(test.value)">
  3. <p>
  4. <textarea style="font-family:fixedsys;font-size:12px;border:1px inset #d3d6d9" cols=40 rows=10 id=ye></textarea>
  5. <script>
  6. var hexcase = 0;  /* hex output format. 0 - lowercase; 1 - uppercase        */
  7. var b64pad  = ""; /* base-64 pad character. "=" for strict RFC compliance   */
  8. var chrsz   = 8;  /* bits per input character. 8 - ASCII; 16 - Unicode      */
  9. /*
  10. * These are the functions you'll usually want to call
  11. * They take string arguments and return either hex or base-64 encoded strings
  12. */
  13. function hex_md5(s)&leftsign; return binl2hex(core_md5(str2binl(s), s.length * chrsz));&rightsign;
  14. function b64_md5(s)&leftsign; return binl2b64(core_md5(str2binl(s), s.length * chrsz));&rightsign;
  15. function hex_hmac_md5(key, data) &leftsign; return binl2hex(core_hmac_md5(key, data)); &rightsign;
  16. function b64_hmac_md5(key, data) &leftsign; return binl2b64(core_hmac_md5(key, data)); &rightsign;
  17. /* Backwards compatibility - same as hex_md5() */
  18. function calcMD5(s)&leftsign; return binl2hex(core_md5(str2binl(s), s.length * chrsz));&rightsign;
  19. /*
  20. * Perform a simple self-test to see if the VM is working
  21. */
  22. function md5_vm_test()
  23. &leftsign;
  24.   return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
  25. &rightsign;
  26. /*
  27. * Calculate the MD5 of an array of little-endian words, and a bit length
  28. */
  29. function core_md5(x, len)
  30. &leftsign;
  31.   /* append padding */
  32.   x[len >> 5] &line;= 0x80 << ((len) % 32);
  33.   x[(((len + 64) >>> 9) << 4) + 14] = len;
  34.   
  35.   var a =  1732584193;
  36.   var b = -271733879;
  37.   var c = -1732584194;
  38.   var d =  271733878;
  39.   for(var i = 0; i < x.length; i += 16)
  40.   &leftsign;
  41.    var olda = a;
  42.    var oldb = b;
  43.    var oldc = c;
  44.    var oldd = d;
  45.    a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
  46.    d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
  47.    c = md5_ff(c, d, a, b, x[i+ 2], 17,  606105819);
  48.    b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
  49.    a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
  50.    d = md5_ff(d, a, b, c, x[i+ 5], 12,  1200080426);
  51.    c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
  52.    b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
  53.    a = md5_ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
  54.    d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
  55.    c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
  56.    b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
  57.    a = md5_ff(a, b, c, d, x[i+12], 7 ,  1804603682);
  58.    d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
  59.    c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
  60.    b = md5_ff(b, c, d, a, x[i+15], 22,  1236535329);
  61.    a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
  62.    d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
  63.    c = md5_gg(c, d, a, b, x[i+11], 14,  643717713);
  64.    b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
  65.    a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
  66.    d = md5_gg(d, a, b, c, x[i+10], 9 ,  38016083);
  67.    c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
  68.    b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
  69.    a = md5_gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
  70.    d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
  71.    c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
  72.    b = md5_gg(b, c, d, a, x[i+ 8], 20,  1163531501);
  73.    a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
  74.    d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
  75.    c = md5_gg(c, d, a, b, x[i+ 7], 14,  1735328473);
  76.    b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);
  77.    a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
  78.    d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
  79.    c = md5_hh(c, d, a, b, x[i+11], 16,  1839030562);
  80.    b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
  81.    a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
  82.    d = md5_hh(d, a, b, c, x[i+ 4], 11,  1272893353);
  83.    c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
  84.    b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
  85.    a = md5_hh(a, b, c, d, x[i+13], 4 ,  681279174);
  86.    d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
  87.    c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
  88.    b = md5_hh(b, c, d, a, x[i+ 6], 23,  76029189);
  89.    a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
  90.    d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
  91.    c = md5_hh(c, d, a, b, x[i+15], 16,  530742520);
  92.    b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);
  93.    a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
  94.    d = md5_ii(d, a, b, c, x[i+ 7], 10,  1126891415);
  95.    c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
  96.    b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
  97.    a = md5_ii(a, b, c, d, x[i+12], 6 ,  1700485571);
  98.    d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
  99.    c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
  100.    b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
  101.    a = md5_ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
  102.    d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
  103.    c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
  104.    b = md5_ii(b, c, d, a, x[i+13], 21,  1309151649);
  105.    a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
  106.    d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
  107.    c = md5_ii(c, d, a, b, x[i+ 2], 15,  718787259);
  108.    b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);
  109.    a = safe_add(a, olda);
  110.    b = safe_add(b, oldb);
  111.    c = safe_add(c, oldc);
  112.    d = safe_add(d, oldd);
  113.   &rightsign;
  114.   return Array(a, b, c, d);
  115.   
  116. &rightsign;
  117. /*
  118. * These functions implement the four basic operations the algorithm uses.
  119. */
  120. function md5_cmn(q, a, b, x, s, t)
  121. &leftsign;
  122.   return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
  123. &rightsign;
  124. function md5_ff(a, b, c, d, x, s, t)
  125. &leftsign;
  126.   return md5_cmn((b & c) &line; ((~b) & d), a, b, x, s, t);
  127. &rightsign;
  128. function md5_gg(a, b, c, d, x, s, t)
  129. &leftsign;
  130.   return md5_cmn((b & d) &line; (c & (~d)), a, b, x, s, t);
  131. &rightsign;
  132. function md5_hh(a, b, c, d, x, s, t)
  133. &leftsign;
  134.   return md5_cmn(b ^ c ^ d, a, b, x, s, t);
  135. &rightsign;
  136. function md5_ii(a, b, c, d, x, s, t)
  137. &leftsign;
  138.   return md5_cmn(c ^ (b &line; (~d)), a, b, x, s, t);
  139. &rightsign;
  140. /*
  141. * Calculate the HMAC-MD5, of a key and some data
  142. */
  143. function core_hmac_md5(key, data)
  144. &leftsign;
  145.   var bkey = str2binl(key);
  146.   if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);
  147.   var ipad = Array(16), opad = Array(16);
  148.   for(var i = 0; i < 16; i++)
  149.   &leftsign;
  150.    ipad[i] = bkey[i] ^ 0x36363636;
  151.    opad[i] = bkey[i] ^ 0x5C5C5C5C;
  152.   &rightsign;
  153.   var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
  154.   return core_md5(opad.concat(hash), 512 + 128);
  155. &rightsign;
  156. /*
  157. * Add integers, wrapping at 2^32. This uses 16-bit operations internally
  158. * to work around bugs in some JS interpreters.
  159. */
  160. function safe_add(x, y)
  161. &leftsign;
  162.   var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  163.   var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  164.   return (msw << 16) &line; (lsw & 0xFFFF);
  165. &rightsign;
  166. /*
  167. * Bitwise rotate a 32-bit number to the left.
  168. */
  169. function bit_rol(num, cnt)
  170. &leftsign;
  171.   return (num << cnt) &line; (num >>> (32 - cnt));
  172. &rightsign;
  173. /*
  174. * Convert a string to an array of little-endian words
  175. * If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
  176. */
  177. function str2binl(str)
  178. &leftsign;
  179.   var bin = Array();
  180.   var mask = (1 << chrsz) - 1;
  181.   for(var i = 0; i < str.length * chrsz; i += chrsz)
  182.    bin[i>>5] &line;= (str.charCodeAt(i / chrsz) & mask) << (i%32);
  183.   return bin;
  184. &rightsign;
  185. /*
  186. * Convert an array of little-endian words to a hex string.
  187. */
  188. function binl2hex(binarray)
  189. &leftsign;
  190.   var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
  191.   var str = "";
  192.   for(var i = 0; i < binarray.length * 4; i++)
  193.   &leftsign;
  194.    str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
  195.           hex_tab.charAt((binarray[i>>2] >> ((i%4)*8  )) & 0xF);
  196.   &rightsign;
  197.   return str;
  198. &rightsign;
  199. /*
  200. * Convert an array of little-endian words to a base-64 string
  201. */
  202. function binl2b64(binarray)
  203. &leftsign;
  204.   var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  205.   var str = "";
  206.   for(var i = 0; i < binarray.length * 4; i += 3)
  207.   &leftsign;
  208.    var triplet = (((binarray[i   >> 2] >> 8 * ( i   %4)) & 0xFF) << 16)
  209.                &line; (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )
  210.                &line;  ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);
  211.    for(var j = 0; j < 4; j++)
  212.    &leftsign;
  213.      if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
  214.      else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
  215.    &rightsign;
  216.   &rightsign;
  217.   return str;
  218. &rightsign;
  219. </script>
复制代码
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
发表于 2005 年 2 月 11 日 21:11:12 | 显示全部楼层
【腾讯云】2核2G云服务器新老同享 99元/年,续费同价
我所知道的原理是:
用JAVASCRIPT
在字符串变量的每个字符中的ASSIC码中加大一位。
在解的时候反正就可以了。
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2005 年 2 月 11 日 21:15:00 | 显示全部楼层
呵呵不错。。楼猪,去我那里灌谁吧哈哈
http://bbs.20ww.com或者做版主
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2005 年 2 月 11 日 21:15:53 | 显示全部楼层
用了速度就慢
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

 楼主| 发表于 2005 年 2 月 11 日 21:18:44 | 显示全部楼层
下面是引用yuke1988于2005-02-11 21:15发表的:
呵呵不错。。楼猪,去我那里灌谁吧哈哈
http://bbs.20ww.com或者做版主
[s:11]
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2005 年 2 月 11 日 21:21:04 | 显示全部楼层
下面是引用yuke1988于2005-02-11 21:15发表的:
呵呵不错。。楼猪,去我那里灌谁吧哈哈
http://bbs.20ww.com或者做版主
难到就是传说中的马夹?
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2005 年 2 月 11 日 21:22:19 | 显示全部楼层
【腾讯云】2核2G云服务器新老同享 99元/年,续费同价
看你这么能灌。。。哈哈,
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

 楼主| 发表于 2005 年 2 月 11 日 21:32:30 | 显示全部楼层
下面是引用yuke1988于2005-02-11 21:22发表的:
看你这么能灌。。。哈哈,
这是罐么
这么经典的帖子你能发的出来么
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

发表于 2005 年 2 月 11 日 21:40:39 | 显示全部楼层
楼上的摇的不错
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

 楼主| 发表于 2005 年 2 月 11 日 21:41:32 | 显示全部楼层
哈哈绝对 扭呀扭
Jgwy.Com - Free Web Hosting Guide & Directory In China since 2001! Jgwy.Net-Jglt.Net
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|金光论坛

GMT+8, 2024 年 11 月 18 日 22:46 , Processed in 0.138608 second(s), 21 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表