Files
ctbjrj/ai助手/zcode预置/skills/dqb-xuanxing/dqb_decode.js
T

27 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// dqb 接口响应解码器(复刻页面 deStr+de:两字符一组 → 数值 → LZW 解压)
// spe 接口=500×(c1-903)+(c2-903);acc 接口=550×(c1-809)+(c2-809)
// 用法: cat 响应 | node dqb_decode.js (spe,默认)
// cat 响应 | node dqb_decode.js acc (acc 附件)
function deStr(t, off, mul) {
var e = [];
for (var s = 0; s + 1 < t.length; s += 2)
e.push(mul * (t[s].charCodeAt() - off) + (t[s + 1].charCodeAt() - off));
return e;
}
function de(t) { // LZW 解压(字典从 256 起)
var e, s, r, a, n = [], i = "", o = 256;
for (e = 0; e < 256; e += 1) n[e] = String.fromCharCode(e);
for (s = String.fromCharCode(t[0]), r = s, e = 1; e < t.length; e += 1) {
a = t[e];
if (n[a]) i = n[a];
else { if (a !== o) return null; i = s + s.charAt(0); }
r += i; n[o++] = s + i.charAt(0); s = i;
}
return r;
}
var fs = require("fs");
var isAcc = (process.argv[2] === "acc");
var input = fs.readFileSync(0, "utf-8");
var text = de(deStr(input.trim(), isAcc ? 809 : 903, isAcc ? 550 : 500));
process.stdout.write(text || "(解码失败)");