This repository has been archived by the owner on Dec 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencoder.ts
104 lines (93 loc) · 2.96 KB
/
encoder.ts
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
const common_patterns = ['andt', 'ment', 'atio', 'ions', 'thec', 'inth', 'ngth', 'here',
'with', 'thei', 'sthe', 'thes', 'ting', 'sand', 'fthe', 'this',
'ethe', 'ofth', 'from', 'ingt', 'that', 'thep', 'dthe', 'ther',
'rthe', 'tthe', 'nthe', 'them', 'othe', 'tion', 'ont', 'eth',
'Int', 'int', 'res', 'all', 'Nth', 'nth', 'oth', 'ate', 'Tha',
'tha', 'sth', 'hat', 'For', 'for', 'fth', 'ati', 'Her', 'her',
'ith', 'ers', 'Ion', 'ion', 'oft', 'est', 'Ent', 'ent', 'his',
'ter', 'Ing', 'ing', 'ver', 'tio', 'And', 'and', 'hes', 'ere',
'The', 'the', ' t', ' T', ' a', ' A', ' i', ' I', ' s', ' S',
' o', ' O', ' w', ' W', ' h', ' H', ' b', ' B', ' c', ' C',
' m', ' M', 'of', 'te', 'Nt', 'nt', 'ou', 'ar', 'St', 'st',
'se', 'ti', 'On', 'on', 'et', 'ea', 'Es', 'es', 'ha', 'or',
'Re', 're', 'is', 'to', 'An', 'an', 'as', 'nd', 'Er', 'er',
'it', 'ed', 'In', 'in', 'al', 'at', 'He', 'he', 'ng', 'en',
'Th', 'th'];
const chars = "×☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !\"#$%&'()*+,-./0123456789:Þ" +
"<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂Ç" +
"üéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞" +
"╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■";
function encode(a: number) {
if (a === 0) {
return chars[0];
}
const l = chars.length;
let b = a;
let base = 1;
let str = "";
while (base <= a) {
str += chars[b % l];
b = Math.floor(b / l);
base *= l;
}
return str;
}
function decode(a: string) {
const l = chars.length;
let base = 1;
let val = 0;
for (let i = 0; i < a.length; i++) {
val += base * chars.indexOf(a[i]);
base *= l;
}
return val;
}
function decodestr(a: string) {
for (let i = 0; i < 32; i++) {
a = a.split(chars[i])
.join(common_patterns[i]);
}
for (let i = 128; i < 256; i++) {
a = a.split(chars[i])
.join(common_patterns[i - 96]);
}
return a;
}
function encodestr(a: string) {
for (var i = 0; i < 32; i++) {
a = a.split(common_patterns[i])
.join(chars[i]);
}
for (var i = 128; i < 256; i++) {
a = a.split(common_patterns[i - 96])
.join(chars[i]);
}
return a;
}
function string_chop(str: string, size: number) {
if (str == null)
return [];
str = String(str);
size = ~~size;
if (size > 0)
return str.match(new RegExp('.{1,' + size + '}', 'g'));
return [str];
}
function encodeLink(a: string) {
try {
return btoa(a.split("").map(i => String.fromCharCode(chars.indexOf(i)))
.join(""))
.replace(/=+$/, '')
} catch (error) {
return escape(a)
}
}
function decodeLink(a: string) {
try {
return atob(a)
.split("").map(i => chars[i.charCodeAt(0)])
.join("")
} catch (error) {
return unescape(a)
}
}