Alok Menghrajani

Security engineer at Square. Previously co-author of Hacklang and pushed for adoption of 100% https at Facebook.

Home | Contact me | Github | Twitter | Facebook

For the last few years, ioccc has been organizing obfuscated coding contests.

The goal is to write short programs in C, in a way that is essentially impossible to read.

One of my all time favorite contributor is Brian Westley, who has written amazing pieces of obfuscated code (and who has won the contest multiple times). One of his entries computes pi. The code is laid out in the shape of a circle and the program works by dividing the area of the code by the "radius" squared.

#define _ F-->00 || F-OO--;
long F=00,OO=00;
main(){F_OO();printf("%1.3f\n", 4.*-F/OO/OO);}F_OO()
{
            _-_-_-_
       _-_-_-_-_-_-_-_-_
    _-_-_-_-_-_-_-_-_-_-_-_
  _-_-_-_-_-_-_-_-_-_-_-_-_-_
 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
  _-_-_-_-_-_-_-_-_-_-_-_-_-_
    _-_-_-_-_-_-_-_-_-_-_-_
       _-_-_-_-_-_-_-_-_
            _-_-_-_
}

Note: as you increase the circular pattern, you'll get a better approximation for the value of pi.

I don't think obfuscated code in JavaScript makes much sense, because it's trivial to encode a program as a string and just eval it.

I did like the idea of laying code in a circular pattern, so I wrote the following piece of JavaScript, which also computes pi:

       <html><body
    id="out"><script>
  setTimeout(function()
 {d = out.parentElement.
outerHTML.replace(/ /g,''
); area=d.length*2;radius
=d.split(/\n/).length;pi=
area / (radius * radius);
pi=(pi * 100 | 0 ) / 100;
 out.innerHTML="pi="+pi
  },1)</script></body>
     h4ck  by   Alok
         </html>

links