4
\$\begingroup\$

Obfuscating things can be incredibly fun:

http://keyboardfire.com/ | license: MIT | contact/email: andy@<website> | enjoy!
(U=function(o){this.Q=o}).prototype.w=function(M){J='ns',H=Math.PI,G='.',T=H|0+G
E=function(b){return b.replace(Q[T],function(b){return h(b.charCodeAt()-H+T)})};
return-M,(l=this.Q)+Array(T).join((h=l.constructor.fromCharCode)(0x79+U.length))
};function F(){}g=((B=function(){return[].slice.call(arguments).join('o')}),F)//
function C(r,p,C){return eval(x="while(p=((p\x7c\1744)-1))C=(C?(C+r)\x3a''+r)")}
Y=C(),(b=new U(g.name+C(x[x=2],-(~-[]*x)))).w();Y=Y.slice(4,7);F.L=25*+([]+H)[T]
f=new U(371..toString(31,Y).replace(/./,function(x){return x.toUpperCase()}));{}
for(i=s=0;i++<F.L;s=Array(+'')+[]){Q=['le','hm',['%',T+74],new RegExp(G,'g',J)];
if(!(i%Y.length))s+=b[unescape(Q[2].join(''))]();i%x.indexOf('(')||Y[[]]||(s+=f.
w());eval(B('c',J,Q[0]))[E(Q[1]).split('').reverse().join(h(C(1)))](s||U.g||i);}

It'd be nice if we could have obfuscation challenges here on PPCG. However, there are a few problems that would arise:

  • First and most obviously, it'd be incredibly difficult to provide an objective winning criterion. "Obfuscated <this task> " can only go so far.

  • Obfuscated code may be malicious, and dangerous to test. This can be partially mitigated by including a "timeline" (like a revision history) that shows the code getting more and more obfuscated, but a sneaky coder could still slip something through. (I promise the example snippet above is safe ;) )

Could we figure out a way to solve these problems, or do we just have to enjoy obfuscating on our own, independently from PPCG? (Perhaps we could create a chatroom for obfuscation, if we can't think of a way to make obfuscation challenges fit the site.)

\$\endgroup\$
  • \$\begingroup\$ The example code looks more golfed than obfuscated. \$\endgroup\$ – Peter Taylor Oct 20 '14 at 15:13
  • 7
    \$\begingroup\$ @PeterTaylor I'm pretty sure FizzBuzz can be shorter than that. ;) \$\endgroup\$ – Doorknob Oct 20 '14 at 16:53
5
\$\begingroup\$

Well, we do have challenges:

All of the above are fine in my opinion, although a question would have to be quite different from the existing ones to be interesting.

Generic code obfuscation is a lot like code trolling: It's fun the first two or three times, but all subsequent challenges are essentially duplicates.

\$\endgroup\$
  • 6
    \$\begingroup\$ Most of the questions tagged underhanded are also about obfuscation. \$\endgroup\$ – Peter Taylor Oct 20 '14 at 15:12
2
\$\begingroup\$

It's not impossible to find an objective winning criterion other than .

You could design or find an algorithm which compares the code to its intended output, or to an unobfuscated program which does the same thing. If we used something simple such as Levenshtein edit distance, then the code which is furthest from the intended output or the unobfuscated sample program would win.

The problem with something as simple as Levenshtein distance is that it doesn't take into account many obfuscation techniques. Suppose that I had to write an obfuscated program that outputs "hello world". In CJam, I could write "ifmmp!xpsme"{(}% (try it here).

If we scored by Levenshtein distance from hello world, this program would score many points. It isn't very obfuscated however:

  1. "ifmmp!xpsme" - place the string ifmmp!xpsme onto the stack
  2. {(}% - treating the string as an array of characters, carry out the ( operation (decrement) on each element
  3. Every character in the string is replaced by the one which precedes it in ASCII. The result is that the string hello world is now on the stack.
  4. At the end of the program, the contents of the stack are printed to standard output.

We need a better algorithm, and I'm not sure that one exists - we could make one ourselves. It would have to take into account Levenshtein distance, simple ASCII shifts like the one I used, and other things. It would be quite hard but not impossible to prepare an official program that calculated the "obfuscation distance" between two strings.

There would, inevitably, be loopholes in the algorithm which people will exploit - so we would have to keep updating the scoring system. Questions might need to be bound to a specific version of the algorithm to avoid having to recalculate scores every time it is updated ("Your score is the obfuscation distance between your program and the output string, according to Obfuscounter 0.8.5. Even if a later version is released, your entry is scored by version 0.8.5.").

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .