Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
loeasy68
GitHub Repository: loeasy68/loeasy68.github.io
Path: blob/main/website/WeirdJS/index.js
2937 views
1
const zero = '+[]';
2
const one = '+!![]';
3
4
const number = n => {
5
if (n === 0) return zero;
6
return Array.from({length: n}, () => one).join(' + ');
7
}
8
9
// C
10
11
const map = {};
12
13
const fromString = s =>s.split('').map(x => {
14
if (!(x in map)) {
15
const charCode = x.charCodeAt(0);
16
return `([]+[])[${fromString('constructor')}][${fromString('fromCharCode')}](${number(charCode)})`;
17
}
18
return map[x];
19
}).join('+');
20
21
map.a = `(+{}+[])[${number(1)}]`;
22
map.b = `({}+[])[${number(2)}]`;
23
map.o = `({}+[])[${number(1)}]`;
24
map.e = `({}+[])[${number(4)}]`;
25
map.c = `({}+[])[${number(5)}]`;
26
map.t = `({}+[])[${number(6)}]`;
27
map[' '] = `({}+[])[${number(7)}]`;
28
map.f = `(![]+[])[${number(0)}]`;
29
map.s = `(![]+[])[${number(3)}]`;
30
map.r = `(!![]+[])[${number(1)}]`;
31
map.u = `(!![]+[])[${number(2)}]`;
32
map.i = `((+!![]/+[])+[])[${number(3)}]`;
33
map.n = `((+!![]/+[])+[])[${number(4)}]`;
34
map.S = `([]+([]+[])[${fromString('constructor')}])[${number(9)}]`;
35
map.g = `([]+([]+[])[${fromString('constructor')}])[${number(14)}]`;
36
map.p = `([]+(/-/)[${fromString('constructor')}])[${number(14)}]`;
37
map['\\'] = `(/\\\\/+[])[${number(1)}]`;
38
map.d = `(${number(13)})[${fromString('toString')}](${number(14)})`;
39
map.h = `(${number(17)})[${fromString('toString')}](${number(18)})`;
40
map.m = `(${number(22)})[${fromString('toString')}](${number(23)})`;
41
map.C = `((()=>{})[${fromString('constructor')}](${fromString('return escape')})()(${map['\\']}))[${number(2)}]`;
42
43
const compile = code => `(()=>{})[${fromString('constructor')}](${fromString(code)})()`;
44
45
const res = compile('console.log("Hello world!");');
46
47
console.log(res);
48
49