6 ms·
Probably similar principles to Brainfuck. Check Wikipedia for an explanation of Brainfuck, I can't come close to doing it justice.
by dlytle 15y ago
Probably similar principles to Brainfuck. Check Wikipedia for an explanation of Brainfuck, I can't come close to doing it justice.
- LeafStorm 15y agoI know how that language works, I'm just surprised that this is capable of pulling off function calls, string concatenations, etc. etc. using only ridiculous type coercions.
- baddox 15y agoAny similarity is coincidental. This hack isn't doing anything semantic or syntactic to the code you provide: it's just encoding the string you provide into an equivalent string in another alphabet. The two alphabets happen to be identical in JavaScript. For example, `+[]` equals the integer 0 (apparently the unary plus operator coerces the empty array to a boolean then converts to an integer), and `![]` of course equals the boolean false. Furthermore, JavaScript does some weird type coercion, so `false + []` equals the string "false". Replace the boolean false with `![]`, so `![] + []` equals the string "false". Now, if we need the letter "f" we just do `"false"[0]`, encoded as `(![] + [])[+[]]`. Remove spaces, and you can see that `(![]+[])[+[]]` is equivalent to "f". People have figured out how to get tons of characters from small initial character sets. See this: http://sla.ckers.org/forum/read.php?24,33349,33405 http://sla.ckers.org/forum/read.php?24,33349,33405