下面这段代码,我想问的是
1.ascii和unascii没有地方引用啊,这两个function是在那个地方起作用的
2.ascii中function($0){return escape($0).replace(/(%u)(\w{4})/gi,"\\u$2")}这一段是什么意思,不懂,特别是&0和&2,不知道这是什么
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body><script style="text/javascript">
function ascii(str){
return str.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"\\u$2")});
}
function unascii(str){
return unescape(str.replace(/\\u/g,"%u"));
}
document.write("\u6ca1\u6709");</script>
</body>
</html>document.write("\u6e05\u534e\u5927\u5b66");</script>
</body>
</html>

解决方案 »

  1.   

    var test = ascii("你好");
    document.write(test);看到画面上打的一串字符\u4F60\u597D
    再执行代码
    alert("\u4F60\u597D");你就知道是怎么回事了这个技术常用来代码混淆
      

  2.   

    我忘了说了,上面这段代码直接就给出了“没有”的结果,可是这个过程有编码转换的过程,应该要用到ascii或者unascii的啊。不太懂这段代码是怎么执行的
      

  3.   

    你这段代码实际上没有调用到ascii和unascii这两个函数,浏览器在处理[\u0000-\uffff]默认是按照unicode编码操作的。其中ascii函数作用是屏蔽unicode编码,unascii实际上是浏览器默认采取的方法,可以不进行调用。经过测试:
    document.write("\u6ca1\u6709");  ---没有
    document.write(unascii("\u6ca1\u6709"));---没有
    document.write(ascii("\u6ca1\u6709"));---\u6ca1\u6709
      

  4.   


    能不能给我解释下ascii后面一段,完全摸不着头脑,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"\\u$2")}这一段....
      

  5.   

    能不能给我解释下ascii后面一段,完全摸不着头脑,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"\\u$2")}这一段....
    $0 是变量
    /gi 是正则全部匹配
      

  6.   


    刚才测试了下,原来这个函数功能不全,不能达到完全代码混淆的功能。而只是对汉字等特殊字符进行了编码。<script>
    var a = 'alert("I am a boy 君")';
    function ascii(str){
    return str.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"\\u$2")});}
    document.write(ascii(a));</script>而lz给出的代码,只是调用了他的结果,而没有调用它的函数
      

  7.   

    你可以先看看这段代码
    <script>
    eval("\u0061\u006c\u0065\u0072\u0074\u0028\u0027\u0042\u006c\u0075\u0065\u0069\u0064\u0065\u0061\u0027\u0029");
    </script>javascript支持用unicode码来执行代码。而你的ascii,恰好完成了其中的对汉字进行加密的功能。但是感觉意义不是很大记得当年攻击google服务器的代码全部经由unicode进行加密,打开js源文件,全部都是这种代码下面给出完整的加密代码
           /**
     * 代码unicode加密
     * 
     * @param target
     */
    function unicodeEncipher(target) { var value = "";
    for (var index = 0; index < target.length; index++) {
    var temp = target.charCodeAt(index).toString(16);
    value += "\\u" + new Array(5 - String(temp).length).join("0") + temp;
    }
    return value;
    }
    alert(unicodeEncipher("你好啊,你家多少人啊.I "));
      

  8.   

    用了国际化给他转码成java的编码了!~