International Obfuscated C Code Contest

IOCCC logo

Source: ioccc.org

Programmers sometimes obfuscate source code in order to make it harder for humans (but not computers) to understand it. For instance, insofar as JavaScript code is often executed client-side, a programmer might want to obfuscate it in order to protect their intellectual property. And some people like to obfuscate code just for fun! Obfuscation itself might involve eliminating unnecessary whitespace and shortening the names of functions and variables to be nondescript, essentially adopting (very!) bad style.

But obfuscation really just makes it harder, not impossible, for humans to understand code. With enough effort, code can be deobfuscated too. (Of course, it might be less effort just to rewrite the same code from scratch!) Let’s convince you of such.

For each of the obfuscated functions below, state what it does and, in no more than three sentences, explain how it works. Assume that any requisite libraries have been included (elsewhere). You’re welcome to copy/paste the code into VS Code in order to style and experiment with it.

  1. (2 points.)

     int f(float x){return(int)(x+0.5);}
    
  1. (3 points.)

     int f(char *s){char*t=s;while(*t!='\0'){t++;}return t-s;}
    
  1. (3 points.)

     long f(int x,int y){long n=1;for(int i=0;i<y;i++){n*=x;}return n;}
    
  1. (4 points.)

     int f(char*s){int r=0;for(int i=0,n=strlen(s);i<n;i++){r+=(s[n-i-1]-'0')*pow(10,i);}return r;}