Skip to content

Instantly share code, notes, and snippets.

@rixtox
Last active December 15, 2015 19:09
Show Gist options
  • Save rixtox/5309315 to your computer and use it in GitHub Desktop.
Save rixtox/5309315 to your computer and use it in GitHub Desktop.
Encode your JavaScript without any quotation mark.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JS NoQuot</title>
<style>
textarea {
font-family: 'consolas';
}
</style>
</head>
<body>
<script>
/*
Principle:
a=~~!!/ / returns 1
b=a<<a 0b0001 << 1 = 0b0010 returns 2
c=b<<a 0b0010 << 1 = 0b0100 returns 4
d=c<<a 0b0100 << 1 = 0b1000 returns 8
e=(d<<a)-a 0b1000 << 1 - a = 0b1111 returns 15
Then we can use the variables above to get binaries
*/
function convert () {
var src = document.getElementById('src').value;
if(document.getElementById('nodigit').checked) {
var out = '', t = {};
switch(document.getElementById('varstyle').value) {
case 'abc':
out = 'a=~~!!/ /,b=a<<a,c=b<<a,d=c<<a,e=(d<<a)-a,';
t = {
0: 'a^a',
1: 'a',
2: 'b',
3: 'b|a',
4: 'c',
5: 'c|a',
6: 'c|b',
7: 'e>>a',
8: 'd',
9: 'd|a',
10: 'd|b',
11: 'e^c',
12: 'd|c',
13: 'e^b',
14: 'e-a',
15: 'e'
};
break;
default:
case '$_':
out = '_=~~!!/ /,_$=_<<_,__=_$<<_,$_=__<<_,$$=($_<<_)-_,';
t = {
0: '_^_',
1: '_',
2: '_$',
3: '_$|_',
4: '__',
5: '__|_',
6: '__|_$',
7: '$$>>_',
8: '$_',
9: '$_|_',
10: '$_|_$',
11: '$$^__',
12: '$_|__',
13: '$$^_$',
14: '$$-_',
15: '$$'
};
break;
}
out += (document
.getElementById('usefunc').checked ? 'Function': 'eval') +
'(String.fromCharCode(';
for(var i in src) {
var b = src.charCodeAt(i).toString(2);
b = Array(5-b.length%4).join('0') + b;
for(var j = 0; j < b.length/4; ++j) {
var s = b.substr((j+1)*-4,4);
out+=Array(j+1).join('(')+t[parseInt(s,2)]+Array(j+1)
.join(')<<' + t[4])+(j<b.length/4-1?'|':'');
}
out+=(i<src.length-1?',':'');
}
} else {
var out = (document.getElementById('usefunc').checked ?
'Function': 'eval') + '(String.fromCharCode(';
for(var i in src)
out += '0x' + src.charCodeAt(i).toString(16) +
(i<src.length-1?',':'');
}
document.getElementById('out').value = out + '))' + (document
.getElementById('usefunc').checked ? '()': '');
}
function changeDigit(e) {
document.getElementById('nodigit').checked
?document.getElementById('varstyle').removeAttribute('disabled')
:document.getElementById('varstyle').setAttribute('disabled')
}
</script>
<center>
<h1>JavaScript NoQuot Converter</h1>
<div style="display: inline-block;">
<textarea id="src" cols="50" rows="30" placeholder="Type your JS
code."></textarea>
<textarea id="out" cols="50" rows="30" disabled></textarea>
<br>
<input type="checkbox" id="usefunc"><label for="usefunc">
Use Function instead of eval</label>
<input type="checkbox" id="nodigit" onchange="changeDigit()">
<label for="nodigit">No Digits</label>
<select id="varstyle" disabled>
<option value="$_">$ and _</option>
<option value="abc">Alphabet</option>
</select>
<br>
<input type="button" value="Convert" onclick="convert()"
style="width:150px;height:20px">
</div>
</center>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment