ascii2native 转码 解码

时间:2024-05-31 21:35:32
 //把十六进制的编码转为原码
function asciiHex2native(strAscii) {
var output = "";
var posFrom = 0;
var posTo = strAscii.indexOf("\\x", posFrom);
while (posTo >= 0) {
output += strAscii.substring(posFrom, posTo);
var s="";
s=strAscii.substr(posTo, 4).replace("\\x","")
var arr=s.split(""), n=arr.length,k=0, s=0
for(var i=0;i<n;i++){
k=n-i-1;
var a=arr[i].toLocaleLowerCase();
if(a=="a"){a=10;}
else if(a=="b"){a=11;}
else if(a=="c"){a=12;}
else if(a=="d"){a=13;}
else if(a=="e"){a=14;}
else if(a=="f"){a=15;}
s+=(a)*Math.pow(16,k);
}
output += String.fromCharCode(s);
posFrom = posTo + 4;
posTo = strAscii.indexOf("\\x", posFrom);
}
output+=strAscii.substring(posFrom);
return ascii2native(output);
} //把正常的ascii编码转为原码
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);
}

如下一段加密的代码:

var FF={"\x48\x6F\x6D\x65":{"\x55\x72\x6C":document["\x55\x52\x4C"],"\x54\x70\x6C":"\x64\x65\x66\x61\x6C\x75\x74","\x43\x68\x61\x6E\x6E\x65\x6C":"","\x47\x65\x74\x43\x68\x61\x6E\x6E\x65\x6C":function (_0xa267x1){if(_0xa267x1=="\x31"){return "\x76\x6F\x64";} ;if(_0xa267x1=="\x32"){return "\x6E\x65\x77\x73";} ;if(_0xa267x1=="\x33"){return "\x73\x70\x65\x63\x69\x61\x6C";} ;} ,"\x4A\x73":function (){this["\x43\x68\x61\x6E\x6E\x65\x6C"]=this.GetChannel(Sid);if($("\x23\x77\x64")["\x6C\x65\x6E\x67\x74\x68"]>0){$key="\u8F93\u5165\u5F71\u7247\u540D\u79F0\u6216\u4E3B\u6F14\u540D\u79F0";if($("\x23\x77\x64")["\x76\x61\x6C"]()==""){$("\x23\x77\x64")["\x76\x61\x6C"]($key);} ;$("\x23\x77\x64")["\x66\x6F\x63\x75\x73"](function (){if($("\x23\x77\x64")["\x76\x61\x6C"]()==$key){$("\x23\x77\x64")["\x76\x61\x6C"]("");} ;} );$("\x23\x77\x64")["\x62\x6C\x75\x72"](function (){if($("\x23\x77\x64")["\x76\x61\x6C"]()==""){$("\x23\x77\x64")["\x76\x61\x6C"]($key);} ;} );} ;$("\x23\x66\x61\x76")["\x63\x6C\x69\x63\x6B"](function (){var _0xa267x2=window["\x6C\x6F\x63\x61\x74\x69\x6F\x6E"]["\x68\x72\x65\x66"];try{window["\x65\x78\x74\x65\x72\x6E\x61\x6C"]["\x61\x64\x64\x46\x61\x76\x6F\x72\x69\x74\x65"](_0xa267x2,document["\x74\x69\x74\x6C\x65"]);} catch(err){try{window["\x73\x69\x64\x65\x62\x61\x72"]["\x61\x64\x64\x50\x61\x6E\x65\x6C"](document["\x74\x69\x74\x6C\x65"],_0xa267x2,"");}

转码后的结果为

var FF={"Home":{"Url":document["URL"],"Tpl":"defalut","Channel":"","GetChannel":function (_0xa267x1){if(_0xa267x1=="1"){return "vod";} ;if(_0xa267x1=="2"){return "news";} ;if(_0xa267x1=="3"){return "special";} ;} ,"Js":function (){this["Channel"]=this.GetChannel(Sid);if($("#wd")["length"]>0){$key="输入影片名称或主演名称";if($("#wd")["val"]()==""){$("#wd")["val"]($key);} ;$("#wd")["focus"](function (){if($("#wd")["val"]()==$key){$("#wd")["val"]("");} ;} );$("#wd")["blur"](function (){if($("#wd")["val"]()==""){$("#wd")["val"]($key);} ;} );} ;$("#fav")["click"](function (){var _0xa267x2=window["location"]["href"];try{window["external"]["addFavorite"](_0xa267x2,document["title"]);} catch(err){try{window["sidebar"]["addPanel"](document["title"],_0xa267x2,"");}