After a one year break, the International Obfuscated C Code Contest is back to showcase the strangest and most challenging-to-comprehend C programs, in the 25th iteration of their event. Their list of awards, announced a few months back, but with the source code of winning projects just released last month, is as idiosyncratic as ever, including the "Most Shifty" C program as well as "Most Likely to be Awarded." Many of these are cryptic hints by judges Leo Broukhis, Simon Cooper, and Landon Curt Noll, who further share their remarks in hint files with (sometimes vague) spoilers. This allows reader to try the programs and discover the behavior of these tiny, strange programs on their own.
Why obfuscate code? And why, in particular, using C? Nothing so directly defies conventional coding standards -- the Dijsktrean aesthetic of clear, self-documenting programs -- than Obfuscated Code, the practice of writing intentionally inscrutible programs. As pointed out in Nick Montfort and Michael Matteas's "A Box Darkly", the aesthetic of IOCCC winners may be at odds with traditional aesthetic of code, but they still assert its C-ness, often using aspects like pointer confusion that less often occur in other languages. Kernighan and Ritchie's slim C book (which many of us used to first learn the langauge) makes the language appear simple and elegant -- but as Montfort and Matteas argue, "clarity in C code is achieved only with effort." The IOCCC winners put their effort toward acheiving the opposite of clarity, exploiting lesser known features of the language, and tactics that fall far from the norms of programming. Even after 25 years, there are winners with novel approaches, such as hou's entry, which makes wonderful use of preprocessor directives and avoids variable names entirely.
Contrast the IOCCC with the much-shorter-run Perl obfuscated code contest. Perl is easy to obfuscate, to the point that the esolangs wiki lists Perl as an esoteric language as is. C is perhaps more fun to obfuscate because its perceived simplicity and air of refinement (along with its continued widespread usage, while Perl now has a very much reduced, if still very enthusiastic userbase). The pleasure of this code is in breaking conventional approaches to discover the little known features, the tricks and hacks. It's a call back to code's beginnings as a dark art before the days of high level languages, an idea analyzed in the early chapters of Wendy Chun's excellent Programmed Visions.
A few notes on some of the winning entries:
"Most cacophonic"
This text-to-speech program by Anton Älgmyr does not work in the ordinary (useful) way. Instead of a machine voice affectlessly reading the text, the program simply maps the shape of the letters into the frequency space, which is then voiced. Here's the output in Audition's waveform and spectral displays, the mp3 following. This is loading with two text files, one to the left channel, one to the right:
This wonderfully useless program is great fun to experiment with, and a depiction of the machine as a meaning-agnostic device, allowing information to be visualised, sonified, or transformed across media in all kinds of absurd ways. The judges claim one can learn to make out what letter is being sounded. "But even without training you can easily read along with printed characters and have the sound make sense with the look of the characters," which are written in a pixel font based on gohufont. I did not find it so easy, although it's a little easier to follow if you watch it progress in Audicity or Audition. The size of the program is exactly 2018 bytes.
Hint file for this entry
"Best tool to reveal holes"
Give the program a text file and a gif is generted to dramatically reveal which of the letters form closed shapes. Another sample file included changes back and forth (in Hebew and transliterated into English) between the words Emeth and meth (golem and death). This is the first of two winning entries by Yusuke Endoh, whose 128+ language quine relay was covered recently here.
"Most inflationary"
Fabrice Bellard -- best known for creating FFMPEG -- is really into image compression. He created his first image compressor, LZEXE, when he was 17, and more recently his own image format called BPG (specification is here), proposed as a succesor for JPEG. This program is strictly a decompressor, using the latest advances in image compression, although the DCT transform with variable block size are the most visible in its visual output. It has the infamous Lena (sometimes "Lenna") image built in -- an image with a long, troubled history in compression studies. For the glitch artists out there, this de-compression scheme creates some wonderful artifacts.
From the judges: "Compressing images is just a matter of simple arithmetic and some magic, isn’t it? We could understand some of the arithmetic but none of the magic."
"Most connected"
#include #include #include typedef unsigned long W; static W*i,t,c,h,e,r,y,**a,*b,*o,*u,*n,*d,*s;enum _ {F=6 , I=7,N= 5 , D = 3 ,M=14 ,Y=0 , C=8,L = 1 , U = 9 , E=4}; static void (* _ ) ( ) ; static void*(*B)(),*T; static char m[0x3543],*Z;void *meltdown(void *p,size_t sz){ void *z=realloc(p,sz);if(!z||!sz)exit(n?y!=*n:I-F); return z;}void magic(W*p){W j;for(j=0;j<p[F];j++){W*v=T,Q= p[M+j];W*J=a[Q];if(N[J]==~0LU){ _ (Q);v=&I[J];}else if(J[D]) {v=&N[J];}if(v&&I[p]>*v)I[p]=*v;}}void cast(void){B(i,Y);}void spell(W G,W H){ _ (); _ (H); _ (H, G); _ (H); _ (G);}void witch( void){e=n[--E[b]];a[e][D]=0;if(b[C]>=U[b]){c=2*(b[C+L]?b[U]:1);o=B (d,c *sizeof*o);u=B(s,c*sizeof*o);b[M-N]=c;d=o;s=u;}d[b[N+D]++]=e;if (e>y)y=e;}void*brew(void*g,size_t l){puts(l?"":"Out of range.");exit (g?1:1);}void newt(W *p){F[p]=0;N[p]=I[p]=~F[p];}void bubble(W H){for (t=0;t<H;t++){s[i[d[H-t-1]]---1]=d[H-t-1];}}void boil(W G){for(t=0;t< G-1;t++){i[t+1]+=i[t];} _ =bubble;}void hex(W G,W H){for(t=0;t<H?G:Y;t++ ){i[d[t]]++;} _ =boil;}void nasal_demons(W G){for (t=Y;t<G;t++)i[t]=0; _ =hex;}void toil(void){i=B(i,y*sizeof*i); _ =nasal_demons;}void bat(W l) {C[b]=0; _ =witch;do _ ();while(e!=l);y++;if(!y)B=brew; _ =toil;spell (C [b],y);printf("%lu:",b[L]++);for(y=0;y<C[b];y++){printf(" %lu",s[y]);}y= 0;puts("");}void potion(W l){W*p=a[l];if(p[N]!=~0LU)return;p[F+L]=h;p[N] =h;p[D]=1;h++;n[b[L+D]++]=l;if(E[b]==r){r*=2;n=B(n,r*sizeof*n);}magic(p) ;if(I[p]==p[N]){bat(l);} _ =potion;}void O(void){n=B(n,2*sizeof(*n));Y[n ]=r;if(a&&a[t]){r=2;b=a[t]; _ =potion;b[L+C]=b[L]^=b[L];E[b]=1;for(y=0;y <*n;y++){if(a[y]){ _ (y);}}} _ =cast;h=0;}void toad(W g,W j,W*l){o=B(a [g],((a[g]?a[g][F]:0)+j+M)*sizeof*o); _ =newt;if(!a[g]){ _ (o);}for(y= 0;y<j;y++){o[F[o]+F+C]=l[y];o[F]++;if(l[y]==g){continue;}u=B(a[l[y]] ,((a[l[y]]?a[l[y]][F]:Y)+M)*sizeof*u);if(!a[l[y]]){ _ (u);}a[l[y]] =u;}y=0;a[g]=o;}void familiar(void){W**w;e=r;if(!r){r=1;}while (r<=t){r*=2;if(!r){B=brew;break;}}w=B(a,r*sizeof*a);if(! Z){Z="\x5f";}for(y=e;y<r;y++){y[w]=T;}y=0;a=w; _ (Y[i] ,c-1,&i[1]);}void spectre(void ){if((W) *Z-060 >011){ return;} _ =toad ;i[c]=( W)atoi( Z);if(i[c]>t){t=i[c];}c++;if(c==h){i=B(i,2*h*sizeof*i);h*=2;}y=i[c-1];if ((Z=strtok(T," \t"))){if(U>=(W)*Z-I*I+L) _ =spectre;}}int main(int argv, char**argc){h++;if(argc){T=argc[argv];} _:_ =O;i=(B=meltdown)(T,h*sizeof *i);while(*argc||Z){c=0;*argc=fgets(m,sizeof(m),stdin); _ =spectre;if(!* argc){Z=T;goto _ ;}Z=strtok(*argc,"\t ");while(Z&&(W)*Z-(M*D+F)<=U){ _ ( );}if(t>=r)familiar();else if(c>0){ _ (i[Y],c-1,&i[1]);}} _ ();goto _ ;}
by Scott Vokes
Shaped as a boiling cauldron, the program is full of textual references to witches, with familiar, spectre (and meltdown!), potion, hex, toil, and so on. "The program reads a directed graph and prints the graph's nodes in reverse-topologically sorted order, grouped into strongly connected components" apparently. It is worth noting that concrete-poetric visual layouts remained popular this year, with most winning entries expressed as shapes with some connection to the content of the work.
"Most shifty"
Don Yang's tool, featuring a character from Girls' Last Tour, rotates any piece of text 90 degrees counter-clockwise. When run on itself, rotating its own source code, it produces a program that rotates clockwise. Continue to rotate the code and more variations are produced, each with their own functionality. You can see hints of this looking at how the code flows: at each corner, there's a #include statement turned one way or another.
It doesn't stop with just the four configurations; run the make file included, and some additional variations are produced, which have minor changes (shifting the numbers in the rodent's [??] face for one thing) that do something slightly different. The work is reminiscent of quine relays, a program with a host of hidden secondary, tertiary, and so on behaviors, exposed only when transformed in a specific way.
"Most able to divine code gaps"
Another cool visualization tool, this one producing character-based art with "lots of squiggly lines" based on the pattern of input text. Above is its portrait of Moby Dick, Chapter 1. Reminds me of Elisabeth S. Clark's Between Words (here on UbuWeb). When running its own source code through it, things align in a more meaningful way.
The Other Winners, in Brief
All the works this year are worth look at; I didn't even list the one marked Best in Show above, so it's worth seeing the judges' notes:
Burton1, "best one-liner" is a hex-dump utility intended to be the smallest. It has some tricky use of memory allocation.
Ciura: "Most likely to be awarded" a Strunk and White serial abuser. A program that marks passive voice statements.
Endoh2: "Best Use of Python," birds and pythons don't mix. A second winning entry from Ysuke Endoh.
Ferguson: "Best use of weasel words" builds on the Infinite Monkey Theorem with weird results.
Giles: "Most unstable" a cellular automaton is used to produce a simulation of sand falling. The code itself resembles a bucket dumping sand.
Mills, "Best of Show" A tiny emulation of PDP-7, the machine Ken Thompson used to write the first version of UNIX. The full description from the judges is worth reading.
Poikola: "Most stellar" draws an animated ASCII art of the Big Dipper using Annie Jump Cannon's spectral classification system of stars. From Poikola: "I also have a strong Perl background, and therefore I added some dollar signs to the code."
Looking forward to the next round (hopefully in 2019)!