zoukankan      html  css  js  c++  java
  • js解密

    <html> <head>    <title>transform between native and ascii</title> </head> <script type="text/javascript"><!--

    var keyStr = "ABCDEFGHIJKLMNOP" +

                  "QRSTUVWXYZabcdef" +

                  "ghijklmnopqrstuv" +

                  "wxyz0123456789+/" +

                  "=";

    function native2ascii(strNative) {

         var output = "";

         for (var i=0; i<strNative.length; i++) {

             var c = strNative.charAt(i);

             var cc = strNative.charCodeAt(i);

             if (cc > 0xff)

               output += "\\u" + toHex(cc >> 8) + toHex(cc & 0xff);

             else

               output += c;

         }

         return output;

    }

    var hexChars = "0123456789ABCDEF";

    function toHex(n) {

         var nH = (n >> 4) & 0x0f;

         var nL = n & 0x0f;

         return hexChars.charAt(nH) + hexChars.charAt(nL);

    }

    function ascii2native(strAscii) {

         var output = "";

         var posFrom = 0;

         var posTo = strAscii.indexOf("\\u", posFrom);

         while (posTo >= 0) {

             output += strAscii.substring(posFrom, posTo);

             output += toChar(strAscii.substr(posTo, 6));

             posFrom = posTo + 6;

             posTo = strAscii.indexOf("\\u", posFrom);

         }

         output += strAscii.substr(posFrom);

         return output;

    }

    function toChar(str) {

         if (str.substr(0, 2) != "\\u") return str;

         var code = 0;

         for (var i=2; i<str.length; i++) {

             var cc = str.charCodeAt(i);

             if (cc >= 0x30 && cc <= 0x39)

                 cc = cc - 0x30;

             else if (cc >= 0x41 && cc <= 0x5A)

                 cc = cc - 0x41 + 10;

             else if (cc >= 0x61 && cc <= 0x7A)

                 cc = cc - 0x61 + 10;

             code <<= 4;

             code += cc;

         }

         if (code < 0xff) return str;

         return String.fromCharCode(code);

    }

    //--></script>

    <body style="font-family: 宋体">

       <form name="theForm">

        Type in the message here, and click a command button:

        <br />

        <textarea name="theText" cols="80" rows="20" wrap="off"></textarea>

        <br />

        <input type="button" value="native to ascii"

         onClick="document.theForm.theText.value=native2ascii(document.theForm.theText.value);">

          <input type="button" value="ascii to native"

         onClick="document.theForm.theText.value=ascii2native(document.theForm.theText.value);">

       </form>

    </body>

    </html>

  • 相关阅读:
    设计模式(Design Pattern)扫盲
    SharePoint 2007 采用表单验证 (1) 失败:(
    发布一款给图片批量加水印的程序PicNet V1.0
    转篇文章,VS2005开发的dll如何安装进GAC
    cnblogs排名进入1500,纪念一下
    转载一篇提高baidu/google收录的文章
    关于.NET(C#)中字符型(Char)与数字类型的转换, CLR via c# 读书笔记
    《天风文章》V1.2.0 新闻/文章类asp.net2.0站点系统源码 (100%开源)
    推荐个.Net的论坛系统 Discuz!NT
    C#实现对图片加水印的一段代码.
  • 原文地址:https://www.cnblogs.com/liuhj/p/2407325.html
Copyright © 2011-2022 走看看