搭建 Charles 激活码生成服务
Haiya Lv3

效果

源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
// index.js
export default {
async fetch(request, env, ctx) {
const { pathname } = new URL(request.url);

if (pathname === "/api/gen") {
const { searchParams } = new URL(request.url);
const name = searchParams.get("name") || "";
if (!name) {
return new Response(JSON.stringify({ error: "缺少 registername" }), {
status: 400,
headers: { "Content-Type": "application/json" },
});
}
try {
const key = crack(name);
return new Response(JSON.stringify({ key }), {
headers: { "Content-Type": "application/json" },
});
} catch (e) {
return new Response(JSON.stringify({ error: "生成失败" }), {
status: 500,
headers: { "Content-Type": "application/json" },
});
}
}

return new Response(
`<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<title>Charles 激活码生成</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
html, body {
margin: 0; padding: 0;
background: #fff;
color: #222;
font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
font-size: 16px;
}
body {
max-width: 600px;
margin: 0 auto;
padding: 32px 12px 24px 12px;
}
h1 {
font-size: 1.1em;
font-weight: 600;
margin: 0 0 1.2em 0;
letter-spacing: 1px;
text-align: left;
}
form {
display: flex;
gap: 8px;
margin-bottom: 1.2em;
}
input[type="text"] {
flex: 1 1 120px;
padding: 5px 8px;
font-size: 1em;
border: 1px solid #bbb;
background: #fff;
color: #222;
outline: none;
border-radius: 0;
}
input[type="text"]:focus {
border-color: #666;
}
button {
padding: 5px 14px;
font-size: 1em;
background: #222;
color: #fff;
border: none;
cursor: pointer;
border-radius: 0;
}
.result-block {
margin-bottom: 1em;
font-size: 1em;
text-align: left;
}
.result-block .row {
display: flex;
align-items: center;
}
.result-block .label {
color: #444;
min-width: 8em;
font-weight: 400;
font-size: 1em;
margin-right: 1em;
}
.result-block .value {
color: #111;
font-weight: 400;
word-break: break-all;
}
.result-block .key-row {
display: flex;
align-items: center;
}
.copy-btn {
background: none;
border: 1px solid #bbb;
color: #222;
font-size: 0.98em;
cursor: pointer;
padding: 2px 10px;
margin-left: 4px;
border-radius: 4px;
}
.copy-btn:active {
background: #eee;
}
.usage {
font-size: 0.97em;
color: #444;
line-height: 1.7;
margin-top: 1.8em;
text-align: left;
}
.usage strong {
color: #111;
font-weight: 600;
}
.usage .warn {
color: #b91c1c;
font-weight: 600;
font-size: 0.97em;
margin-top: 0.7em;
display: block;
}
</style>
</head>
<body>
<h1>Charles 激活码生成</h1>
<form id="f" autocomplete="off">
<input id="name" type="text" placeholder="输入 RegisterName" required autocomplete="off" />
<button type="submit">生成</button>
</form>
<div class="result-block" id="resultBlock" style="display:none;">
<div class="row"><span class="label">Registered Name:</span><span class="value" id="regName"></span></div>
<div class="row key-row">
<span class="label">License Key:</span>
<span class="value" id="licenseKey"></span>
<button class="copy-btn" id="copy" type="button" style="display:none;">复制</button>
</div>
</div>
<div class="usage">
<strong>用法:</strong><br>
输入 <strong>RegisterName</strong>(此名称随意,用于显示 Registered to xxx),点击生成计算出注册码,页面会显示注册名和注册码。<br>
打开 Charles,输入注册名和注册码即可激活。<br>
<span class="warn">注意:仅供个人学习研究和交流使用,请勿用于任何商业用途。</span>
</div>
<script>
const f = document.getElementById('f');
const resultBlock = document.getElementById('resultBlock');
const regName = document.getElementById('regName');
const licenseKey = document.getElementById('licenseKey');
const copyBtn = document.getElementById('copy');
let lastKey = "";
f.onsubmit = async e => {
e.preventDefault();
const name = document.getElementById('name').value.trim();
if (!name) {
resultBlock.style.display = "none";
return;
}
regName.textContent = "生成中…";
licenseKey.textContent = "";
resultBlock.style.display = "block";
copyBtn.style.display = "none";
try {
const r = await fetch('/api/gen?name=' + encodeURIComponent(name));
const d = await r.json();
if (d.key) {
regName.textContent = name;
licenseKey.textContent = d.key;
lastKey = d.key;
copyBtn.style.display = "";
} else {
regName.textContent = "";
licenseKey.textContent = d.error || "生成失败";
copyBtn.style.display = "none";
}
} catch {
regName.textContent = "";
licenseKey.textContent = "网络错误";
copyBtn.style.display = "none";
}
};
copyBtn.onclick = () => {
if (!lastKey) return;
navigator.clipboard.writeText(lastKey);
copyBtn.textContent = "已复制";
setTimeout(() => { copyBtn.textContent = "复制"; }, 1200);
};
</script>
</body>
</html>`,
{ headers: { "content-type": "text/html; charset=utf-8" } }
);
},
};

// --- 激活码算法移植自 Go ---

const rounds = 12;
const roundKeys = 2 * (rounds + 1);

function crack(text) {
const name = new TextEncoder().encode(text);
const length = name.length + 4;
const padded = ((-length) & (8 - 1)) + length;
const bs = new Uint8Array(4);
new DataView(bs.buffer).setUint32(0, name.length, false); // big endian
const buff = new Uint8Array(padded);
buff.set(bs, 0);
buff.set(name, 4);

const ckName = BigInt("0x7a21c951691cd470");
const ckKey = BigInt("-5408575981733630035");
const ck = newCkCipher(ckName);

const outBuff = [];
for (let i = 0; i < padded; i += 8) {
const bf = buff.slice(i, i + 8);
let nowVar = new DataView(bf.buffer).getBigInt64(0, false); // big endian
let dd = ck.encrypt(nowVar);
for (let j = 7; j >= 0; j--) {
outBuff.push(Number((dd >> BigInt(j * 8)) & BigInt(0xff)));
}
}

let n = 0;
for (const b of outBuff) {
n = rotateLeft32(n ^ (b << 24 >> 24), 0x3);
}
const prefix = n ^ 0x54882f8a;
let suffix = Math.floor(Math.random() * 0x7fffffff);
let inVal = (BigInt(prefix) << 32n);
let s = BigInt(suffix);
switch (suffix >> 16) {
case 0x0401:
case 0x0402:
case 0x0403:
inVal |= s;
break;
default:
inVal |= BigInt(0x01000000) | (s & BigInt(0xffffff));
break;
}
const out = newCkCipher(ckKey).decrypt(inVal);

let n2 = 0n;
for (let i = 56; i >= 0; i -= 8) {
n2 ^= (inVal >> BigInt(i)) & 0xffn;
}
let vv = Number(n2 & 0xffn);
if (vv < 0) vv = -vv;
return `${vv.toString(16).padStart(2, "0")}${out.toString(16).padStart(16, "0")}`;
}

function newCkCipher(ckKey) {
const rk = new Array(roundKeys).fill(0);
let ld = [Number(ckKey & 0xffffffffn) | 0, Number((ckKey >> 32n) & 0xffffffffn) | 0];
rk[0] = -1209970333;
for (let i = 1; i < roundKeys; i++) {
rk[i] = (rk[i - 1] + -1640531527) | 0;
}
let a = 0, b = 0, i = 0, j = 0;
for (let k = 0; k < 3 * roundKeys; k++) {
rk[i] = rotateLeft32((rk[i] + (a + b)) | 0, 3);
a = rk[i];
ld[j] = rotateLeft32((ld[j] + (a + b)) | 0, (a + b));
b = ld[j];
i = (i + 1) % roundKeys;
j = (j + 1) % 2;
}
return {
encrypt: function (input) {
let a = Number(input & 0xffffffffn) + rk[0];
let b = Number((input >> 32n) & 0xffffffffn) + rk[1];
a |= 0; b |= 0;
for (let r = 1; r <= rounds; r++) {
a = (rotateLeft32((a ^ b), b) + rk[2 * r]) | 0;
b = (rotateLeft32((b ^ a), a) + rk[2 * r + 1]) | 0;
}
return pkLong(a, b);
},
decrypt: function (input) {
let a = Number(input & 0xffffffffn) | 0;
let b = Number((input >> 32n) & 0xffffffffn) | 0;
for (let i = rounds; i > 0; i--) {
b = rotateRight32((b - rk[2 * i + 1]) | 0, a) ^ a;
a = rotateRight32((a - rk[2 * i]) | 0, b) ^ b;
}
b = (b - rk[1]) | 0;
a = (a - rk[0]) | 0;
return pkLong(a, b);
}
};
}

function rotateLeft32(x, y) {
y &= 31;
return ((x << y) | (x >>> (32 - y))) | 0;
}
function rotateRight32(x, y) {
y &= 31;
return ((x >>> y) | (x << (32 - y))) | 0;
}
function pkLong(a, b) {
return (BigInt(a >>> 0) | (BigInt(b >>> 0) << 32n));
}
由 Hexo 驱动 & 主题 Keep