-
Notifications
You must be signed in to change notification settings - Fork 7
/
machine.js
138 lines (115 loc) · 3.97 KB
/
machine.js
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
(function () {
var MEMORY = [];
var CODE = [];
var COUNTER = 0;
while (true) {
switch (CODE[COUNTER++]) { // in reality, these codes would be random
case 1233: // allocate/set memory STRING
MEMORY[CODE[COUNTER++]] = decryptString();
break;
case 1234: // allocate memory/set INT
MEMORY[CODE[COUNTER++]] = CODE[COUNTER++];
break;
case 1235: // allocate memory/set ARRAY
MEMORY[CODE[COUNTER++]] = [];
break;
case 1236: // allocate memory/set OBJECT
MEMORY[CODE[COUNTER++]] = {};
break;
case 1237: // Addition
MEMORY[CODE[COUNTER++]] = MEMORY[CODE[COUNTER++]] + MEMORY[CODE[COUNTER++]];
break;
case 1238: // subtraction
MEMORY[CODE[COUNTER++]] = MEMORY[CODE[COUNTER++]] - MEMORY[CODE[COUNTER++]];
break;
case 1239: // multiplication
MEMORY[CODE[COUNTER++]] = MEMORY[CODE[COUNTER++]] * MEMORY[CODE[COUNTER++]];
break;
case 1240: // division
var r = MEMORY[CODE[COUNTER++]] = MEMORY[CODE[COUNTER++]] / MEMORY[CODE[COUNTER++]];
break;
case 1241: // compare:
var code = CODE[COUNTER++];
var a = MEMORY[CODE[COUNTER++]];
var b = MEMORY[CODE[COUNTER++]];
var fal = CODE[COUNTER++];
var value = false;
switch (code) {
case 0: // equal to
value = a == b
break;
case 1: // bigger than
value = a > b
break;
case 2: // bigger than or equal
value = a >= b
break;
case 3: // smaller than
value = a < b
break;
case 4: // smaller than or equal
value = a <= b
break;
}
if (!value) COUNTER = fal;
break;
case 1242: // goto:
COUNTER = CODE[COUNTER++];
break;
case 1243: // console.log
console.log(decryptStringComp(MEMORY[CODE[COUNTER++]]));
break;
case 1244: // IntToString
var integ = MEMORY[CODE[COUNTER++]].toString();
var st = [];
for (var i = 0; i < integ.length; ++i) {
st.push(integ.charCodeAt(i));
}
MEMORY[CODE[COUNTER++]] = st;
break;
case 1245: // end
return;
break;
case 1246: // concat string/array
MEMORY[CODE[COUNTER++]] = MEMORY[CODE[COUNTER++]].concat(MEMORY[CODE[COUNTER++]])
break;
case 1247: // get length
MEMORY[CODE[COUNTER++]] = MEMORY[CODE[COUNTER++]].length
break;
case 1248: // slice/substr
MEMORY[CODE[COUNTER++]] = MEMORY[CODE[COUNTER++]].slice(MEMORY[CODE[COUNTER++]], MEMORY[CODE[COUNTER++]])
break;
case 1249: // push
MEMORY[CODE[COUNTER++]].push(MEMORY[CODE[COUNTER++]]);
break;
case 1250: // splice
MEMORY[CODE[COUNTER++]].splice(MEMORY[CODE[COUNTER++]], MEMORY[CODE[COUNTER++]], MEMORY[CODE[COUNTER++]]);
break;
case 1251: // get
MEMORY[CODE[COUNTER++]] = MEMORY[CODE[COUNTER++]][MEMORY[CODE[COUNTER++]]];
break;
case 1252: // set
MEMORY[CODE[COUNTER++]][MEMORY[CODE[COUNTER++]]] = MEMORY[CODE[COUNTER++]];
break;
};
}
function decryptString() {
var str = [];
while (true) {
var code = CODE[COUNTER++];
if (!code) break;
str.push(code);
}
return str
}
function decryptStringComp(ar) {
var str = [];
var i = 0;
while (true) {
var code = ar[i++];
if (!code) break;
str.push(String.fromCharCode(code));
}
return str.join("")
}
})()