It is time once again for The International Obfuscated C Code Contest, the IOCCC. For those of you who don't know what it is check out http://www.ioccc.org/ which IMO is one of the best designed web sites on the entire internet.

Even though I don't plan on participating I still enjoy looking through the entries and past winners just to see if I can figure out what they do. Any aspiring programer can learn a lot, or be confused beyond comprehension by looking through some of these masterpieces of valid C code. I encourage all of you to take a look and see if you can figure any out.
C? More like Perl.
Just a look quick through there yielded me a spambot thwarter. Useful stoff.
allynfolksjr wrote:
C? More like Perl.
Perl doesn't need any obfuscation; it's already plenty obfuscated writing it normally. Jonimus, I always enjoy getting my mind blown looking through some of their winners. I can't say I've ever considered entering, but it certainly looks like fun.
KermMartian wrote:
allynfolksjr wrote:
C? More like Perl.
Perl doesn't need any obfuscation; it's already plenty obfuscated writing it normally. Jonimus, I always enjoy getting my mind blown looking through some of their winners. I can't say I've ever considered entering, but it certainly looks like fun.

In 2005 or 2006 I wanted to enter the contest, but I was sad to see that they didn't open the next contest that year. I was even sadder to see they didn't open the contest the next year either. By 2008 I had lost hope that they would ever open the contest again. Now I'm happy to see that it's open again! Hurray! Very Happy

Unfortunately, I've lost most interest in entering it now. Maybe I'll enter one of my old obfuscated programs I wrote for the contest years ago just for kicks and giggles. I have no expectations to win, what with all the very impressive entries of years past.
Entering Smile
Ashbad, good luck; do you know what you'll be submitting? Christop, you should totally do it!
Sadly I was not a winner of this year's contest, but that means I can finally share with you guys the diabolicalness I cooked up.


Code:
//*/ Convenient macros for short code
#define cant(M) printf(CTEXT, M); r = 1; goto x
#define die printf(TRM)
#define fpc fclose(fp)
#define c(A, B) calloc(A, B)

// short type parameters for common case
typedef const unsigned short cs;
typedef unsigned short * N;
typedef N ( *Tf )(int, cs *);
#define SV int m, cs * n
size_t S = sizeof ( cs );
size_t C = sizeof ( char );
int i; // impose recursion limit in loops

// make char goto short for UTF-16
N ns(const char * s){
   size_t m = strlen(s);
   N n = c(m, S);
   for(i = 0; i < m and n; i++) n[i] = *( s + i );
   return n;
}

// do (or break) Caesar-cipher
N gm(SV, int sgn){
   N nn = c(m, S);
   for(i = 0; i < m and nn; i++) nn[i] = ( n[i] + ( sgn * 7 ) );
   return nn;
}

N m(SV){ return gm(m, n, -1); }
N am(SV){ return gm(m, n, +1); }

// Helpers to align message header & body.
// For UTF-16 char count of each row: add padding if row is short
N b(SV, int l){
   N o = c(l ? 16 * m : m / 16, S);
   int j, p, k = 0;
   for(i = 0; i < m / ( l ? 1 : 16 ) and o; i++)
   {
      /* dead code path */
      // int pid = fork();
      // if (pid == -1) return NULL;
      //*/
      for(j = 15; j >= 0; j--)
      {
         p = 1 << j;
         %:define e1se ;
         o[l ? k++ : i] = l ?
         %:define lf(N) goto *a[N]; if(N)
         !!( n[i] & p ) : n[k++] * p;
      }
   }
   return o;
}

N s(SV){ return b(m, n, 1); }
N rh(SV){ return b(m, n, 0); }

// avoid memory leaks
N slf(SV){ return (N) (free((void *)n), 0); }

cs hd[2][4] = { {0, 0xFEFF, 1, 2}, {3, 4, 0, 0}};
Tf tf[5] = {&slf, &m, &am, &s, &rh};
int main(int c, const char * rgs[]){
   int r = 000, front = 007, end = 010, x, y, w, h;
   size_t nb = DS;
   char * tx;
   unsigned short *m[3] = {0, 0, 0};
   void * a[] = { and u, and u, and u, and u, and u, and d, and m, and x, and mm, and start};
   FILE * fp;

   // initialization and input error handling
start:
   lf(c < front ? c : r){
      goto d;
   }
   
u:
   r = !!printf(HT, rgs[r]);
   lf(front){
      goto d;
   }
d:
   tx = c(nb, C);
   strcpy(tx, DM);
   lf(end){
      goto start;
   }
x:
   return r % 1;
m:
   if((fp = fopen(rgs[5], "rb"))){
      fseek(fp, 0L, SEEK_END);
      nb = ftell(fp);
      fseek(fp, 0L, SEEK_SET);
      tx = c(nb, C);
   } else lf(r) {
      cant(OPEN);
   } e1se {
      r %= 2;
   }

   if(tx){
      fread(tx, C, nb, fp);
      fpc;
      while( ( tx[--nb] <= 32 ) and ( nb < LONG_MAX ) ) tx[nb] = 0;
      nb++;
   } else lf(r) {
      cant(BUFFER);
      die;
   }


   lf(end){
      goto x;
   }
mm:

   // read image from file
   pm_init(rgs[r], 0);
   bit * *g;

   if((fp = fopen(rgs[1], "rb"))){
      g = pbm_readpbm(fp, &w, &h);
   } else lf(r) {
      cant(OPEN);
   } e1se {
      r %= 5;
   }

   if(g){
      fpc;
   } else lf(r) {
      cant(BUFFER);
      die;
   }

   int xst = 16 * atoi(rgs[3]);
   int yst = 16 * atoi(rgs[4]);

   int lup, lpr = nb % 2, mS = 2 * (int)( nb / 2 + ( lpr ? 4 : 3 ) );
   #define msg m[2]
   msg = c(mS, S);

   for(r = !lpr; r < 4; r++) msg[r - !lpr] = hd[0][r];

   m[1] = ns(tx);
   free(tx);

   // clear (from left) swath of pixels for message
   for(r = 0; r < nb; r++) msg[4 + r - !lpr] = *( m[1] + r );
   for(r = 2; r >= 0; r--)   msg[mS - 3 + r] = hd[1][r];

   // blit message buffer onto row 0
   for(r = 0; r < 5; r++) m[r < 2 | r > 3] = tf[r % 2 ? r : 0](mS, m[1 + !( r < 1 | r > 2 )]);

   // rotate image front-to-back
   int mM = mS * 8;
   int z, f = mM - ( mM % 16 );
   mM *= 2;
   for(y = yst, lup = 0; lup < mM; lup += f, y++){
      z = !lup;
      int lc = !z ? f : mM - f;
      x = xst + ( !z ) * ( ( lc + lc / 8 + lc / 56 ) );
      int rst = z ? 0 : mM - 1;
      #define dnk(V) ( !lup ? V++ : V-- )
      for( r = rst; z ? r < f : r >= f; dnk(r) ){
         if(  r < f and !( r % 8 )  or  r >= f and !( ( rst - r ) % 8 ) ){
            dnk(x);
            if( !( x % 8 ) ){
               dnk(x);
            }
         } e1se {
            g[y][x] = m[0][r];
            dnk(x);
         }
      }
   }
   r %= 1;

   // prepare output buffer
   // could go earlier, here is fine
   if((fp = fopen(rgs[2], "wb"))){
      pbm_writepbm(fp, g, w, h, 0);
      fpc;
   } else lf(r) {
      cant(OPEN);
      die;
   }

   // blit message buffer onto row 1
   for(r = 0; r < 5; r++) m[!(r % 3)] = tf[r % 2 ? 0 : 4 - r]((r ? 1 : 16) * mS, m[!(r < 2 | r > 3)]);

   // check image orientation, do 2nd pass
   lf(front) {
      goto mm;
   }

   // call it a day & return accumulated status code
   return r % 7;
}


It's worth noting that this program also breaks the official IOCCC size tool, causing it to emit the number 32 instead of the actual size of my program source.

If anyone else enjoys this sort of thing, I'd appreciate feedback.

Let me know if you want the Makefile to try to building it yourself for stepping-through.
Now I'm happy to see that it's open again! Hurray! Very Happy
In 2005 or 2006 I wanted to enter the contest, but I was sad to see that they didn't open the next contest that year. I was even sadder to see they didn't open the contest the next year either. By 2008 I had lost hope that they would ever open the contest again.
http://www.ioccc.org/
Just when I had hoped that technical brilliance can be learnt and nurtured, I now realise that these people are from a different planet.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement