-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.html
177 lines (176 loc) · 5.15 KB
/
index.html
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!DOCTYPE HTML>
<head>
<title>Horrible.js</title>
<script>
/* horrible.js - a JS compiler that does horrible things.
* Thomas NJ Shadwell
* Licensed under the MIT license.
* Usage: window.compile(<string>, <string>)
* Argument 1: The code to compile.
* Argument 2: A (preferably very short) variable name you don't use.
* window.horror- Horrible factor:
* Factor 1: As normal
* Factor 2: Encode numbers as mess
* Factor 3: Encode numbers and charcodes
* window.constructor:
* Method to execute code from string.
*/
var numberToMess = function (num) {
if (num == 0) return "(+[])";
else if (num == 1) return "(+!+[])";
else {
var str = "";
for (var d = 0; d < num; d++) {
str += "!+[]+";
}
return "+" + str.slice(0, -1);
}
}
var stringToCharCodeArrayString = function (string) {
cc = [];
for (var i = 0; i < string.length; ++i) {
cc[i] = string.charCodeAt(i);
}
if (window.horror == 3) {
cc = cc.map(numberToMess);
}
return cc.join(",");
}
var constructors=[
"_=\"constructor\"_[_][_]",
"_=([![]]+{})[+!+[]+[+[]]]+([]+[]+{})[+!+[]]+([]+[]+[][[]])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+(!![]+[])[!+[]+!+[]]+([![]]+{})[+!+[]+[+[]]]+(!![]+[])[+[]]+([]+[]+{})[+!+[]]+(!![]+[])[+!+[]];_[_][_]",
"(![]+[])[+[]][([![]]+{})[+!+[]+[+[]]]+([]+[]+{})[+!+[]]+([]+[]+[][[]])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+(!![]+[])[!+[]+!+[]]+([![]]+{})[+!+[]+[+[]]]+(!![]+[])[+[]]+([]+[]+{})[+!+[]]+(!![]+[])[+!+[]]][([![]]+{})[+!+[]+[+[]]]+([]+[]+{})[+!+[]]+([]+[]+[][[]])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+(!![]+[])[!+[]+!+[]]+([![]]+{})[+!+[]+[+[]]]+(!![]+[])[+[]]+([]+[]+{})[+!+[]]+(!![]+[])[+!+[]]]",
]
window.constructo=";_=\"constructor\";_[_][_]";
window.dict = {
'a': '(![]+[])[+!+[]]',
'b': '([]+[]+{})[!+[]+!+[]]',
'c': '([![]]+{})[+!+[]+[+[]]]',
'd': '([]+[]+[][[]])[!+[]+!+[]]',
'e': '(!![]+[])[!+[]+!+[]+!+[]]',
'f': '(![]+[])[+[]]',
'i': '([![]]+[][[]])[+!+[]+[+[]]]',
'j': '([]+[]+{})[+!+[]+[+[]]]',
'l': '(![]+[])[!+[]+!+[]]',
'N': '(+{}+[]+[])[+[]]',
'n': '([]+[]+[][[]])[+!+[]]',
'O': '(![]+[]+[]+[]+{})[+!+[]+[]+[]+(!+[]+!+[]+!+[])]',
'o': '([]+[]+{})[+!+[]]',
'r': '(!![]+[])[+!+[]]',
's': '(![]+[])[!+[]+!+[]+!+[]]',
't': '(!![]+[])[+[]]',
'u': '(!![]+[])[!+[]+!+[]]',
' ': '(+{}+[]+[]+[]+[]+{})[+!+[]+[+[]]]',
'[': '([]+[]+{})[+[]]',
']': '([]+[]+{})[+!+[]+[]+[]+(!+[]+!+[]+!+[]+!+[])]'
}
var compileToString = function (codeasstring, extrasvalue) {
window.cacheNumbers=[];
window.horror = document.getElementById("horror").value;
var c = " " + codeasstring;
var out = "";
var extras = "";
for (var i = 0, chr = ''; i < c.length; i++, chr = c[i]) {
if (i != 0) {
if (chr in dict) {
out += dict[chr] + "+";
} else {
if (extras.indexOf(chr) == -1) {
extras += chr;
}
if (window.horror == 1) {
out += extrasvalue + "[" + extras.indexOf(chr) + "]+";
} else {
out += extrasvalue + "[" + numberToMess(extras.indexOf(chr)) + "]+";
}
}
}
}
return extrasvalue + "=String.fromCharCode(" + stringToCharCodeArrayString(extras) + ");" + out.slice(0, -1);
}
var compile = function (codeasstring, extrasvalue) {
m = compileToString(codeasstring, extrasvalue).split(";");
return m[0] + ";"+ window.constructo + "(" + m[1] + ")();";
}
window.code = {
compile: function () {
document.getElementById("compiledCode").value = compile(
document.getElementById("code").value,
document.getElementById("shortvar").value
);
},
compileToString: function () {
document.getElementById("compiledCode").value = compileToString(
document.getElementById("code").value,
document.getElementById("shortvar").value
);
}
}
</script>
<style type="text/css">
input{
display: block;
}
input[type="radio"]{
display: inline;
}
body{
width:700px;
margin-left:auto;
margin-right:auto;
}
textarea{
position:relative;
width:100%;
height:500px;
}
#code:before{
display:block;
font-size:20px;
content:"Code to compile...";
}
#compiledCode:before{
display:block;
font-size:20px;
content:"Compiled code...";
}
head{
display:block;
}
title,script{
white-space: pre;
font-family:monospace;
font-size:15px;
color:black;
display:block;
border-bottom:1px solid black;
}
title{
font-size:30px;
}
a{
text-decoration:none;
color:black;
border:1px solid black;
padding:10px;
cursor:pointer;
}
a+a{
border-left:0px;
}
</style>
</head>
<body>
Horror factor:<input id="horror" value="1" type="range" min="1" max="3" step="1" />
Short var:<input id="shortvar" type="text" value="$"/>
Function constructor:<br/>
<form>
<input type="radio" onclick="window.constructo=constructors[0]" name="const" value="constructor">"constructor".</input>
<input type="radio" onclick="window.constructo=constructors[1]" name="const" value="hec">Horrible encoded constructor.</input>
<input type="radio" onclick="window.constructo=constructors[2]" name="const" value="100h">100% horrible.</input>
</form>
<textarea id="code"></textarea>
<a onclick="code.compile()"><i>compile</i> from text</a>
<a onclick="code.compileToString()"><i>compileToString</i> from text</a>
<textarea id="compiledCode"></textarea>
</body>