I saw a very cool security talk a few years ago about how you can use the browser to do all kinds of evil things (did you know that the Same Origin Policy does not prevent you from making the request, but just seeing the response? And even then, you can guess at what kind of response you got). One of the great points in the talk was JS obfuscation. Now, there are many techniques for doing this, but I really like this…
JSFuck – Write any JavaScript with 6 Characters: []()!+
31–40 of 76 posts
Re: JSFuck – Write any JavaScript with 6 Characters: []()!+
#32Re: JSFuck – Write any JavaScript with 6 Characters: []()!+
#33Re: JSFuck – Write any JavaScript with 6 Characters: []()!+
#34Which breaks down to: [!+[]+!+[]] === [2] +[[!+[]+!+[]]] === 2 [+[[!+[]+!+[]]]] === [2] //again
So I think there might be quite a bit of scope for compression even within the parameters it's built in.
Highly impressive, in any case.
Re: JSFuck – Write any JavaScript with 6 Characters: []()!+
#35I put in alert('hello') and it worked. That's awesome. But how? I searched the code it made and didn't see 'hello.' I understand the stuff below, how it uses JS's weird properties to the basic types... but how does it encode characters?
For instance, to get the string "a":
(![]+[])[+[[+!+[]]]]
Take the first part, `(![]+[])`. `![]` evaluates to `false`. Then `+[]` coerces false into a string, so the expression is `"false"`.The rest of the expression (more complicated) evaluates to `[[1]]`, which will grab the `"a"` from `"false"`. Now why there is the extra surrounding brackets, I'm not sure, because `[1]` would have worked as well.
Re: JSFuck – Write any JavaScript with 6 Characters: []()!+
#36Re: JSFuck – Write any JavaScript with 6 Characters: []()!+
#37"JSFuck is an esoteric and educational programming style" How exactly is this educational?
In order to get particular characters (for example: f), the script uses "false"[0], where "false" is derived from adding ![] + [], and 0 is derived from +[].
Putting all of that together ($ node):
> (![]+[])[+[]]
'f'
Re: JSFuck – Write any JavaScript with 6 Characters: []()!+
#38How long will it take till we see a decompiler? :D
Re: JSFuck – Write any JavaScript with 6 Characters: []()!+
#39Earlier quoted context omitted.
It's probably easier (and much smaller) to put all js in a file, convert it to a data-URI and add it into the html.
That isn't obsfucation though.