r/programming • • Aug 10 '12

Write any javascript code with just these characters: ()[]{}+!

http://patriciopalladino.com/blog/2012/08/09/non-alphanumeric-javascript.html
1.3k Upvotes

288 comments sorted by

View all comments

-3

u/wickedhood Aug 10 '12

The website doesn't work. It just freezes when you try to convert a script.

16

u/nemec Aug 10 '12

How large of a script are you converting?

alert(1) becomes

[][(![]+[])[!+[]+!![]+!![]]+({}+[])[+!![]]+(!![]+[])[+!![]]+(!![]+[])[+[]]]({}+[])[!+[]+!![]+!![]+!![]+!![]]+{}+[])[+!![]]+([][+[]]+[])[+!![]]+(![]+[])[!+[]+!![]+!![]]+(!![]+[])[+[]]+(!![]+[])[+!![]]+([][+[]]+[])[+[]]+({}+[])[!+[]+!![]+!![]+!![]+!![]]+(!![]+[])[+[]]+({}+[])[+!![]]+(!![]+[])[+!![]][!+[]+!![]+!![]]+([][+[]]+[])[!+[]+!![]+!![]])()(({}+[])[+[]])[+[]]+(!+[]+!![]+!![]+[])+{}+[])[!+[]+!![]]))()

So I imagine a larger script will take a while to convert.

-3

u/stumac85 Aug 10 '12

Exactly - I don't get the point of this whatsoever! Is it meant to be useful?!

4

u/Nodules Aug 10 '12

What does it matter? The dude who made this found it fun/interesting to do so, and that's what matters.

Of course it isn't particularly useful. No-one in their right mind would use this for production (or even development) code. He did it because he could.

2

u/nemec Aug 10 '12

It's not meant to be useful, specifically (though OP did mention it could be used to circumvent certain security measures (like checking that "eval" isn't in the input or something).

It's more akin to Obfuscated C contests: http://www.ioccc.org/years.html

1

u/KimJongIlSunglasses Aug 10 '12

though OP did mention it could be used to circumvent certain security measures

This is the part I'm unclear on.
Are there application architectures in which a user submits arbitrary javascript to be executed server side and are only secured by some static code analysis?

1

u/nemec Aug 10 '12

Sometimes people try to implement their own (crappy) XSS prevention mechanisms, some of which consist of input.replace('eval', '').replace('alert', '').replace(';', '')...

→ More replies (1)

2

u/alcuadrado Aug 10 '12

Try converting a smaller script or do it in node.js. Browsers can't handle that much of javacript without freezing