# Convert JSF**k to normal JS

Many of you already know JSF**k. For those who don't, it's a script that basically turns any JavaScript code into something written using only []()!+.

Your task is to build, using any language of your choice, a program which converts JSF**k into unobfuscated JavaScript.

• Input: A string with valid JSF**k code.
• Output: A string with the regular JavaScript code that has been previously JSF**ked to generate the input.

For this challenge, consider that the input string has only been JSF**ked once.

This is a contest, so the shortest code, in bytes, wins.

• @Michael but is the encoding unambiguously revertible? I don't think so... how do I decide if a some [...] array access was part of the original code or part of the obfuscation? same for all other constructs, really. – Martin Ender May 28 '14 at 19:10
• @JanDvorak oh what... that's so counter-productive... we could help him out with closing this question and upvoting instead of downvoting. – Martin Ender May 28 '14 at 19:16
• @m.buettner I've downvoted because I don't feel the question is going anywhere. I definitely don't want to upvote a post just to unlock some privileges for someone. – John Dvorak May 28 '14 at 19:17
• @JanDvorak I think we shouldn't discourage new users who want to write good challenges and listen to criticism. Since the sandbox is on meta and will stay there, downvoting is counter-productive. Closing is totally sufficient. I don't think a single upvote would harm anyone, and it would give the user the chance to actually find an entry into this community. But someone agreed with you and decided to downvote as well, because heck, why should new users be allowed to post in the sandbox (I guess)... and now he still can't post there. I don't think that's how we grow this community. – Martin Ender May 28 '14 at 19:49
• Can you please add some explanation what normal JavaScript means? It might not be obvious how the back-transformation has to be done. E.g. if I iterate the obfustator twice on some nice input, what is the suggested output? The original program or the input which was already obfuscated? – Howard May 29 '14 at 11:36

# Javascript - 6855 51

alert(/\n(.+)/.exec(eval(prompt().slice(0,-2)))[1])


Alternatively: (same length)

alert(/.+(?=\n})/.exec(eval(prompt().slice(0,-2))))


Runs in the console of your browser. Only guaranteed to work with code generated by jsfuck.com with the 'Eval Source' option ticked.

Ungolfed:

alert(
/\n(.+)/.exec(                 // regex to extract code from inside outer function braces {}
eval(prompt().slice(0,-2)) // remove the final set of parens () and evaluate the code
// this results in a function, which will be converted to a string as 'exec' expects a string
)[1]                           // get the first capture group
)

• In a suggested edit that I rejected, @user3082537 suggested to use regex instead of slice, as in replace(/^.*\n|\n}\$/g,'') – ace May 29 '14 at 13:12

# JavaScript, 122, works with any input

s=prompt().slice(0,-2)
i=s.length

Pretty simple; it just goes back in the string until the parentheses (( and )) are balanced. The last three characters of the JSF output are always )(), so slicing off the last 2 parens and then finding the matching paren for the other will always work. (It works with input with [] too.)