# 求混淆js加密算法解密

3 个回答
• 147

``````// 填入响应数据的url字段
let res_formats_url = '65326f655953386f68336f645166616852434f754b2f4c323747706f387937354f4f72667a7a497a4e2b5a7a33754d63664b71616a56497a414c38754943716450695a705a75326f6e4f476f696e633165533977736d595a67534a626157347050436169697139324633626d2f537177506671736c754c357931486c4a324a6e6a7147706e3273737475476a51537170704732664a4b366e7568476e662b596763715a685561366e566561666c79706e6c364e313453386d667a647261432b7447486133437670344d7a4a6f70717334714b2b6e'

// 填入响应数据的token字段

let url = main(res_formats_url, res_token)
console.log(url)``````
``````// 入口函数
function main(t, n) {   // t 为响应结果的 url, n 为响应结果的 token
if (!t || !n)
return null;
, s = /\/build\/bundle-([^"]+?).css/g.exec(o);
if (!s)
return "";
var i = s[1]
, c = hex2bin(t).split("").reverse().join("")
, l = n + document.location.hostname.length + i;
return decrypt(c, l)
}

// 十六进制转二进制
function hex2bin(e) {
var t, n = [], r = 0;
for (t = (e += "").length; r < t; r += 2) {
var a = parseInt(e.substr(r, 1), 16)
, o = parseInt(e.substr(r + 1, 1), 16);
if (isNaN(a) || isNaN(o))
return !1;
n.push(a << 4 | o)
}
return String.fromCharCode.apply(String, n)
}

// 数据解密
function decrypt(e, t) {
var n = "";
e = decode64(e);
for (var r = 0; r < e.length; r++) {
var a = e.substr(r, 1)
, o = t.substr(r % t.length - 1, 1);
a = Math.floor(ord(a) - ord(o)),
n += a = String.fromCharCode(a)
}
return n
}

// base64解码
function decode64(e) {
if (e = e.replace(/\s/g, ""),
/^[a-z0-9\+\/\s]+\={0,2}\$/i.test(e) && !(e.length % 4 > 0)) {
var t = 0
, n = void 0
, r = void 0
, a = [];
for (e = e.replace(/=/g, ""); t < e.length;) {
switch (n = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".indexOf(e.charAt(t)),
t % 4) {
case 1:
a.push(String.fromCharCode(r << 2 | n >> 4));
break;
case 2:
a.push(String.fromCharCode((15 & r) << 4 | n >> 2));
break;
case 3:
a.push(String.fromCharCode((3 & r) << 6 | n))
}
r = n,
t++
}
return a.join("")
}
}

function ord(e) {
var t = "" + e
, n = t.charCodeAt(0);
if (n >= 55296 && n <= 56319) {
var r = n;
return 1 === t.length ? n : 1024 * (r - 55296) + (t.charCodeAt(1) - 56320) + 65536
}
return n
}``````