The International Obfuscated C Code Contest

The International Obfuscated C Code Contest (IOCCC) has just opened their latest round. Entried close in Frebruary. The purpose of this competition is to write C code in the most obscure way possible. Reading through last years winning entries I found some real gems. It’s amazing how much functionality these people manage to cram into such a small space. Does this suggest a change in programming paradims? Small rather than elegant?

Here are my favourites…

Table of Contents

Skyes

A full 6502 processor and Commodore PET 2001 emulator.


#include
#include
#include
#define P *p
#define E (s?s-1?s-2?
#define T (s=fgetc(g))
#define _ m[n&
#define L R(
#define b ):L
#define G ):(
#define r =t&
#define F _++k+O]
#define W t--?t--?
#define Y _ k--+O]=
#define M W W W W W W W
#define J *E&D:&V:&I:&C)
#define q C|Z|I|D|B|V|S|32
#define H E Z:C:V:S)&&(d+=P&l?P-O:P)
#define U(z,w)(t=w,d+=z,_ t]+_ t+1]*O)
int d,C,Z,I,D,B,V,S,i=49152
,t,s,o,h,z,O=256,n=65535,l=128,f=255,e,w; unsigned char*p,m[65536],a,x,y,k,*u,
*j=" ./ p/ 7 ] . 6 6 p t7 r(0)1*+2,4WgcovGn^f_NVO>F?TswldiHZYI9QJ"
"RCKSL[b<d8AP:;a@`BXq3j=- HZYI9QJRCKSL[b<d8AP:;a@`BX 57 ; ; ; ; "
" ; "
" )< <% <% '< <% +< <% 7$ ($A @$A "
"($A &$ $A *$ $A C2 2; =2; 62; '2 2; +2 2; D# #B ?#B 6#B &# #B "
"*# #B F HFG 1 L HFG 'F HFG NFM F :89 :89 J8I :89 &8 :89 +8K :89 ., "
".,/ 5,0 .,/ ', ,/ +, ,/ -E -E3 4E -E3 &E E3 *E E3 2133024425660788"
; R(x){ Z=x?0:2; S=x&l; } K(x){ R(x-P); C=x

1?v[1]:"", j+32); t=i; if(g) { ;
for(; T+1;
_ t++ ]=s);
w r /* ### COMMODORE BASIC ### */n ;
d=w?i: U(C, n
-3); /* READY. */z=c>
2?atoi( v[2])+1
:4; c=z ? n * z
/ 4 : n; nodelay(
initscr( ), 1 ) ;
curs_set(I); cbreak(); noecho( ) ; for (; ;
) { o++ % ( c *4) ?h :( h= getch () ,h-ERR?(_
162]=h|l):0); if(!w){ s=(_ 59408]
|=z?l:0)&15; _ 59410]=~(h-ERR?(s^8?0:j[h|l]&1)|(j[h]/8
-5-s?0:1<<j[h]%8):0); } o%c|I||N(); p=m +O+O+ _ l-9]; t
=d%65493; i=_ d++]; if(w+t<4){ if(P&&(u=strchr(++p,34)))
{ *u=0; _ l-9]=u-m+1; if(g=fopen(p,t?j+61:j+32)){ i=1025
-t; if(!t){ T; for(T; T+1; _ i++]=s); for(p=m+42; p>6; t=j[i+O]-35; M M M W 0 : L a = y G k = x G L
a=x)G L x = k ) G L y=a)G L x = a ) G P =y G P = x G P
=a G t=a-P-1+C,C r O?0:1,V=((a^ P ) & ( a ^ t )&l)/2 , L a r
f)G d=F,d+=F*O+1 G A(),d=F,d|=F*O G t=P,L P=P/2|C*l),C r 1 G t=P,L P=P*2|
C),C=t/l):A(b a=F G Y q G Y a G L a|=P)G C=P&1,L P/=2)G L y=P)b x=P b a=P G
s=U(1,--d),X(),d=s G d=i&32?U(0,e):e b++y b++x b++P b a^=P b--y b--x b--P):
K(y):K(x):K(a G J=0 G J=E 8:8:4:1)G d--,B=16,N() G L a&P),V=P&64
,S=P&l):!H:H:(C=P/l,L P*=2)b a&=P G t=a+P+C,C r O?1:0,V=(~(a^P)&

(a^t)&l)/2,L a r f)); t=e^O*O/2; if(ts?attron(i)
:attroff(i); mvaddch(t/40,t%40,s+w95+w?s-32:s); } } } perror(*v); }

Toledo

A chess program, capable of playing both two player and single player against the PC.


#define F getchar())
#define H(z)*n++=z;
#include
#define v main(0,0,0
#define Z while(
#define _ if(
#define o(d) (u[l]=0,l[d]=6^e,q=1e4>v,0),l[d]=0,u[l]=e^6,q)
#define I(H,n) { _ r=l[x=H],!r|(r^e)<-1){ _ j=u[l],-7==r|6==r
){ n; e=~e; return 1e5- f; } u[l]=0,t=j+1,i=j-1; _!i&89x)t=j,i=-7; Z++i<t){ b=S; d=0; S&=63;
a=((j^e)!=1?6!=(j^e)?O[32+x/10]-O[u/10+32]-q:(S|=6!=j?8
:1,2==u-x)*9+9*(x-u==2):(d=1==j?x-u:u-x)/8+!(!((x-u)%
10)|r)*99+(j==1?90x)*(9*O[28+i]-288))+O[r+28
]*9-288+O[x%10+33]-f-O[33+u%10]; x[l]=i; S|=(21=
=u|21==x)*2+(u==28|28==x)*4+(91==u|x==91)*16+32
*(u==98|x==98)+(20==d)*64*x; a-=k>f?main(a,f+1
,M,k):0; _ i==c&u==h&!f&N&a>-1e4&x==y)longjm
p(z,1); S=b; _!N|f&&(a>M||!f&a==M&&1&rand()
)){ _!f){ _ k){ c=i; h=u; y=x; } } else _
L-aGK[_`fFDZXEYR" "Lt####"
"##B#A#@#G#F#E#D#Kt3Zlv#tjm" "3J#tjm3Pwb"
"ofnbwf3Joofdbo3)&`&`.&`&`" "#+&g*t"; G y,
c,h,e,S,*s,l[149]; jmp_buf z ; G main(G L,G f,
G N,G k){ G u=99,p,q,r,j,i,x ,t, a, b,d,M=-1e9
; char *n; if( *l){ e=~e; Z u >21){ q= l[--u]^e;
_!-- q){ _!l[p=e?u-10:u+10]){ I(p,)_ e?u>80 & !l[p
-=10]:u>6){ l[u-1]=0; I(p,l[u-1]=-2^e); } _ l[
p=e?u-9:11+u])I(p,)else _ S>>6==1+u){ l[1+u]=0; I(p,l
[1+u]=e^-2); } } _!--q){ n=O+41; Z++n<50+O)I(u+80-*n,
)} _ 0q){ n=q==2?53+O:O+49; Z++n<o+(q!=1)*4+54
){ p=u; do I(p-=*n-80,)Z!p[l]); } } _ 4==q){ n=49+O
; Z++n<o+58)I(u-*n+80,)_ e&!(S&24)|!e&!(S&3)&&k&&
!l[u-2]&!l[u-1]&!l[u-3]&&o(u)&o(u-1)){ l[u-1]= 4
^e; l[u-4]=0; I(u-2,l[u-1]=0; l[u-4]=e^4); } _
e&!(S&40)|!e&!(S&5)&&k&&!l[u+1]&!l[2+u]&&o(u)&
o(1+u)){ l[u+1]=e^4; l[3+u]=0; I(u+2,l[1+u
]=0; l[u+3]=4^e); } } } e=~e; return M; }
Z hh|98(h+1 )%
10); O[h++]^=3; } n=O +14; s=20+l; Z
++s<29+l){ 10[s]=1; 70[s]=~ ( * s = *
n++ -+84); 60 [ s] =-2; } Z n=J){ puts
(58+O); u=19; Z++u7){ H(58
-u/10)H(32)_ u&1)puts(n=J); } } puts
(O+58); _-1e4 >v , 1)){ e=~e; puts
(O+(v,0)> 1e4?e?90:82:96)); break
; } _ 11&&u!=c
[O]); c=e^c-7; } } _!
setjmp(z)){ v+1,1);
puts( 106+
O); } } Z
10!=
F; }

Vik

A simple rasterized 3D game engine, a la Wolfenstein style.


#include
#include
#include
#include
#include
#include
Window L;
GC N;
Display *K;
XEvent O;
XImage *Q;
float w, x, y[7 << 16];
struct timeval S, U;
int a, b, c, d =
92, e, f, g, h, i, j, k, l, m, n, o, p, *q[96], r[7 <b=b+32*o,B->c=c+32*X,B->d=Y,B->e=C,B++->a=l,
#define D(o,X)(int)((X*(B->b-e)-o*(B->c-f))/(x*B->e-w*B->d))

int
main (int X, char **Y)
{
for (j = J <b;
k >> 8 ? 0 : (l = D (B->d, B->e), l > 0
&& l a : 0, B++);
for (;
X
&& (p =
1 | 3 * (o = (--X < 2 || 119 - 1[Y[1]] ? 320 : atoi (2[Y]))) / 4);)
{
for (e = f = J / 2, K = XOpenDisplay (0); m < o <> 3 & m)), r[m++] =
m / 18 <> 6 ^ m)));
for (N =
XCreateGC (K, L =
XCreateSimpleWindow (K, RootWindow (K, 0), 0, 0, o, p,
0, 0, 0), 0, 0), ((I =
fopen (X ?
Y[X]
: "",
"r")) ?
fread (E + 1,
1,
1 < 54 && l > 8 | C << 16, *u =
n, 0 b;
*H = *G++, H += !B->b)
for (B = A + J / 3;
B->b && !(B != G && B->b == G->b - 128 * (B->d - G->d)
&& B->c == G->c - 128 * (B->e - G->e)); B++);
for (Q =
XCreateImage (K, DefaultVisual (K, 0), DefaultDepth (K, 0),
ZPixmap, 0, (char *) (v =
malloc (4 * o * p)), o, p,
32, 0);
d = (d + R[19] - R[17]) & 127, n = R[18] - R[20], n ? (i =
o * 128 +
d + (n
200) ? e +=
(int) (y[i] * 64), f += (int) (y[i + 32] * 64) : 1 : 1;
XSync (K, 0), gettimeofday (&S, 0), m = T - S.tv_usec)
{
for (T -=
(m > 0
&& m > 1, m = 0;
k =
1 +
(int) (p * 512 /
((i = m * P + d, g = n =
0, main (0, Y)) * y[m * P + 32])), m < o; m++)
for (t = g ? c =
64 * s[g], q[g] + h / 4 + 64 * (a / 3 % s[g]) : t;
l = 32 - (17 << (k < 2)) * (2 * n - p) / k, n

> 6 ? 4477904 << (l < 0) : t[c * l]);
for (XPutImage (K, L, N, Q, 0, 0, 0, 0, o, p); XPending (K);
R[63 & XLookupKeysym (&O.xkey, 0 & XNextEvent (K, &O))] ^=
O.type == KeyPress || O.type == KeyRelease);
}
}
return j;
}

I wonder how small they could make Windows or Office.

Leave a Reply