12
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ @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. \$\endgroup\$ – Martin Ender May 28 '14 at 19:10
  • 2
    \$\begingroup\$ @JanDvorak oh what... that's so counter-productive... we could help him out with closing this question and upvoting instead of downvoting. \$\endgroup\$ – Martin Ender May 28 '14 at 19:16
  • 2
    \$\begingroup\$ @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. \$\endgroup\$ – John Dvorak May 28 '14 at 19:17
  • 2
    \$\begingroup\$ @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. \$\endgroup\$ – Martin Ender May 28 '14 at 19:49
  • 1
    \$\begingroup\$ 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? \$\endgroup\$ – Howard May 29 '14 at 11:36
12
\$\begingroup\$

Javascript - 68 55 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
)
\$\endgroup\$
  • \$\begingroup\$ In a suggested edit that I rejected, @user3082537 suggested to use regex instead of slice, as in replace(/^.*\n|\n}$/g,'') \$\endgroup\$ – ace May 29 '14 at 13:12
7
\$\begingroup\$

JavaScript, 122, works with any input

s=prompt().slice(0,-2)
i=s.length
while(i--){if((l=s.slice(i)).split(')').length==l.split('(').length)break}alert(eval(l))

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.)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.