I saw a lot of replies talking about Brainfuck which is an esoteric programming language ( used for fun ) and not a web developing language so for me the most difficult language for developing a website is JSFuck.
JSFuck is an esoteric subset of JavaScript, where code is written using only six characters: [, ], (, ), !, and +.
JSFuck Unlike Brainfuck, which requires its own compiler or interpreter, JSFuck is valid JavaScript code, meaning that JSFuck programs can be run in any web browser or engine that interprets JavaScript.
Let’s to write the
alert("Hello, world!")
can be written as
Function('alert("Hello, world!")')
Now each character of the string alert("Hello, world!")
can be written using only the 6 characters +!()[]
in a tricky way. For a start, let’s just look at the letter “a”, how it’s written in JSFuck:
- “a”: is the second character of the string false (index 1 counting from 0)…
- “false”[1] : “false” can be made from false+[], i.e. the boolean constant false plus an empty array…
- (false+[])[1]: we write false as ![] (negation applied to an empty array)…
- (![]+[])[1]: 1 is a number, we can write it as +true…
- (![]+[])[+true]: since false is ![], true is !![]…
(![]+[])[+!![]] «< that’s it!
In a few steps, the letter “a” has been converted into pure JSFuck code. Other characters can be much harder to produce, but over the years, tricky ways have been found to write any character using only the characters allowed in JSFuck. Anyway, those can be quite long strings for each character, and that’s why a simple “Hello, world!” program in JSFuck takes up more that 10000 characters!
But let’s come back to our example: after all JSFucked characters are joined back together like "a"+"l"+"e"+"r"+"t"+...
, there’s still the Function(...)()
part to convert. Function
in JavaScript is the constructor of any function, so if we can get a function somehow, and then get its constructor, we’re done. In fact, Function in JSFuck is made from []["filter"]["constructor"]
, i.e., the “constructor” property of the “filter” property of an empty array. The strings “filter” and “constructor” are just sequences of characters, and we already know that there’s always a tricky way to write each character.
Now I think you know how to write letters in JSFuck but what if we need to write some numbers.
0 => +[] 1 => +!+[] 2 => !+[]+!+[] 10 => +[[+!+[]]+[+[]]]
The number 0 is created by +[], where [] is the empty array and + is the unary plus, used to convert the right side to a numeric value (zero here). The number 1 is formed as +!![] or +!+[], where the boolean value true (expressed as !![] or !+[] in JSFuck) is converted into the numeric value 1 by the prepended plus sign. The digits 2 to 9 are formed by summing true the appropriate number of times. E.g. in JavaScript true + true = 2 and true = !![] = !+[], hence 2 can be written as !![]+!![] or !+[]+!+[]. Other digits follow a similar pattern. Integers consisting of two or more digits are written, as a string, by concatenating 1-digit arrays with the plus operator. For example, the string “10” can be expressed in JavaScript as [1] + [0]. By replacing the digits with the respective JSFuck expansions, this yields [+!+[]]+[+[]]. To get a numeric value instead of a string, one would enclose the previous expression in parentheses or square brackets and prepend a plus, yielding 10 = +([+!+[]]+[+[]]).
To summarize this is the sheet Cheat of JSFuck basics :
false => ![] true => !![] undefined => [][[]] NaN => +[![]] 0 => +[] 1 => +!+[] 2 => !+[]+!+[] 10 => +[[+!+[]]+[+[]]] Array => [] Number => +[] String => []+[] Boolean => ![] Function => []["filter"] run => []["filter"]["constructor"]( CODE )() eval => []["filter"]["constructor"]("return eval")()( CODE ) window => []["filter"]["constructor"]("return this")()