Update lib/snapsave/util.js
Browse files- lib/snapsave/util.js +10 -13
lib/snapsave/util.js
CHANGED
@@ -13,25 +13,21 @@ export function getDecodedSnapSave(data) {
|
|
13 |
|
14 |
export function decryptSnapSave(data) {
|
15 |
const args = getEncodedSnapSave(data);
|
16 |
-
if (args.length
|
17 |
-
throw new Error("
|
18 |
}
|
19 |
const decoded = decodeSnapSave(...args);
|
20 |
return getDecodedSnapSave(decoded);
|
21 |
}
|
22 |
|
23 |
export function decodeSnapSave(...args) {
|
24 |
-
if (args.length < 6) {
|
25 |
-
throw new Error("Invalid SnapSave decryption arguments.");
|
26 |
-
}
|
27 |
-
|
28 |
let [h, u, n, t, e, r] = args;
|
29 |
-
|
30 |
function decode(d, e, f) {
|
31 |
const g = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/'.split('');
|
32 |
let h = g.slice(0, e);
|
33 |
let i = g.slice(0, f);
|
34 |
-
|
35 |
let j = d.split('').reverse().reduce((a, b, c) => {
|
36 |
let index = h.indexOf(b);
|
37 |
return index !== -1 ? a + index * Math.pow(e, c) : a;
|
@@ -45,9 +41,10 @@ export function decodeSnapSave(...args) {
|
|
45 |
return k || '0';
|
46 |
}
|
47 |
|
48 |
-
|
|
|
49 |
for (let i = 0, len = h.length; i < len; i++) {
|
50 |
-
let s =
|
51 |
while (h[i] !== n[e]) {
|
52 |
s += h[i];
|
53 |
i++;
|
@@ -55,8 +52,8 @@ export function decodeSnapSave(...args) {
|
|
55 |
for (let j = 0; j < n.length; j++) {
|
56 |
s = s.replace(new RegExp(n[j], "g"), j.toString());
|
57 |
}
|
58 |
-
|
59 |
}
|
60 |
|
61 |
-
return decodeURIComponent(encodeURIComponent(
|
62 |
-
}
|
|
|
13 |
|
14 |
export function decryptSnapSave(data) {
|
15 |
const args = getEncodedSnapSave(data);
|
16 |
+
if (args.length < 6) {
|
17 |
+
throw new Error("Invalid SnapSave decryption arguments.");
|
18 |
}
|
19 |
const decoded = decodeSnapSave(...args);
|
20 |
return getDecodedSnapSave(decoded);
|
21 |
}
|
22 |
|
23 |
export function decodeSnapSave(...args) {
|
|
|
|
|
|
|
|
|
24 |
let [h, u, n, t, e, r] = args;
|
25 |
+
|
26 |
function decode(d, e, f) {
|
27 |
const g = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ+/'.split('');
|
28 |
let h = g.slice(0, e);
|
29 |
let i = g.slice(0, f);
|
30 |
+
|
31 |
let j = d.split('').reverse().reduce((a, b, c) => {
|
32 |
let index = h.indexOf(b);
|
33 |
return index !== -1 ? a + index * Math.pow(e, c) : a;
|
|
|
41 |
return k || '0';
|
42 |
}
|
43 |
|
44 |
+
// Remove duplicate `let r`
|
45 |
+
let result = '';
|
46 |
for (let i = 0, len = h.length; i < len; i++) {
|
47 |
+
let s = '';
|
48 |
while (h[i] !== n[e]) {
|
49 |
s += h[i];
|
50 |
i++;
|
|
|
52 |
for (let j = 0; j < n.length; j++) {
|
53 |
s = s.replace(new RegExp(n[j], "g"), j.toString());
|
54 |
}
|
55 |
+
result += String.fromCharCode(decode(s, e, 10) - t);
|
56 |
}
|
57 |
|
58 |
+
return decodeURIComponent(encodeURIComponent(result));
|
59 |
+
}
|