Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
titaniumnetwork-dev
GitHub Repository: titaniumnetwork-dev/Ludicrous
Path: blob/main/encoding.ts
1223 views
1
const xor: any = {
2
key: 2,
3
encode(str: String | undefined, key: number) {
4
if (!key) key = xor.key;
5
if (!str) return str;
6
var encoded: any = eval(`encodeURIComponent((str).split('').map((char,ind)=>ind%2?String.fromCharCode(char.charCodeAt()^2):char).join(''));`);
7
if (!encoded.endsWith('/')) return encoded;
8
else return encoded
9
},
10
decode(str: string | undefined, key: Number | String | undefined) {
11
if (!key) key = xor.key;
12
if (!str) return str;
13
str = str.replace(new RegExp('\/$', 'g'), '');
14
var encoded: any = eval(`(decodeURIComponent(str).split('').map((char, ind) => ind % 2 ? String.fromCharCode(char.charCodeAt() ^ 2) : char).join(''));`);
15
return encoded;
16
}
17
}
18
19
const plain: any = {
20
encode(str: string | undefined) {
21
if (!str) return str;
22
var encoded = (str)
23
return encoded;
24
},
25
decode(str: string | undefined) {
26
if (!str) return str;
27
var encoded = decodeURIComponent(decodeURIComponent(str));
28
return str.replace('https://','https:/').replace('https:/','https://');
29
}
30
}
31
32
const base64: any = {
33
encode(str: string | undefined) {
34
if (!str) return str;
35
var encoded = btoa(encodeURIComponent(str));
36
if (!encoded.endsWith('/')) return encoded;
37
else return encoded
38
},
39
decode(str: any | undefined) {
40
if (!str) return str;
41
str = str.replace(new RegExp('\/$', 'g'), '');
42
var encoded = decodeURIComponent(atob(str));
43
return encoded;
44
}
45
}
46
47
export default {xor, plain, base64};
48