Chaque année à lieu le Concours International du Code C Obscur - The International Obfuscated C Code Contest. L'objectif ?
- Ecrire un programme C le plus obscur possible. (il y a quand même des règles à respecter)
- Montrer l'importance du style dans la programmation, de façon ironique
- De mettre les compilateurs C à l'épreuve avec du code tordu
- D'illustrer quelques subtilités du langage C
Inutile de précisier qu'ils ont un humour qui fait mouche chez moi...
Voici quelques morceaux choisis. Oui, ça compile, et oui, ces programmes remplissent une fonction !
This program takes a single command line argument, transcribes the argument text into Tolkien's Elvish letters, and writes the transcription to standard output as a portable graymap (PGM) file.
#include\
#include
#include
#define w "Hk~HdA=Jk|Jk~LSyL[{M[wMcxNksNss:"
#define r"Ht@H|@=HdJHtJHdYHtY:HtFHtF=JDBIl"\
"DJTEJDFIlMIlM:HdMHdM=I|KIlMJTOJDOIlWITY:8Y"
#define S"IT@I\\@=HdHHtGH|KILJJDIJDH:H|KID"\
"K=HdQHtPH|TIDRJDRJDQ:JC?JK?=JDRJLRI|UItU:8T"
#define _(i,j)L[i=2*T[j,O[i=O[j-R[j,T[i=2*\
R[j-5*T[j+4*O[j-L[j,R[i=3*T[j-R[j-3*O[j+L[j,
#define t"IS?I\\@=HdGHtGIDJILIJDIItHJTFJDF:8J"
#define y yy(4),yy(5), yy(6),yy(7)
#define yy( i)R[i]=T[i],T[i ] =O[i],O[i]=L [i]
#define Y _(0 ], 4] )_ (1 ], 5] )_ (2 ], 6] )_ (3 ], 7] )_=1
#define v(i)( (( R[ i ] * _ + T [ i ]) * _ + O [ i ]) * _ + L [ i ]) *2
double b = 32 ,l ,k ,o ,B ,_ ; int Q , s , V , R [8 ], T[ 8] ,O [8 ], L[ 8] ;
#define q( Q,R ) R= *X ++ % 64 *8 ,R |= *X /8 &7 ,Q=*X++%8,Q=Q*64+*X++%64-256,
# define p "G\\QG\\P=GLPGTPGdMGdNGtOGlOG" "dSGdRGDPGLPG\\LG\\LHtGHtH:"
# define W "Hs?H{?=HdGH|FI\\II\\GJlHJ" "lFL\\DLTCMlAM\\@Ns}Nk|:8G"
# define U "EDGEDH=EtCElDH{~H|AJk}" "Jk?LSzL[|M[wMcxNksNst:"
# define u "Hs?H|@=HdFHtEI" "\\HI\\FJLHJTD:8H"
char * x ,*X , ( * i )[ 640],z[3]="4_",
*Z = "4,8O4.8O4G" r U "4M"u S"4R"u t"4S8CHdDH|E=HtAIDAIt@IlAJTCJDCIlKI\\K:8K"U
"4TDdWDdW=D\\UD\\VF\\FFdHGtCGtEIDBIDDIlBIdDJT@JLC:8D"t"4UGDNG\\L=GDJGLKHL\
FHLGHtEHtE:"p"4ZFDTFLT=G|EGlHITBH|DIlDIdE:HtMH|M=JDBJLDKLAKDALDFKtFKdMK\
\\LJTOJ\\NJTMJTM:8M4aGtFGlG=G|HG|H:G\\IG\\J=G|IG|I:GdKGlL=G|JG|J:4b"W
S"4d"W t t"4g"r w"4iGlIGlK=G|JG|J:4kHl@Ht@=HdDHtCHdPH|P:HdDHdD=It\
BIlDJTEJDFIdNI\\N:8N"w"4lID@IL@=HlIH|FHlPH|NHt^H|^:H|MH|N=J\\D\
J\\GK\\OKTOKDXJtXItZI|YIlWI|V:8^4mHLGH\\G=HLVH\\V:4n" u t t
"4p"W"IT@I\\@=HdHHtGIDKILIJLGJLG:JK?JK?=JDGJLGI|MJDL:8M4\
rHt@H|@=HtDH|BJdLJTH:ITEI\\E=ILPILNNtCNlB:8N4t"W t"4u"
p"4zI[?Il@=HlHH|HIDLILIJDII|HKDAJ|A:JtCJtC=JdLJtJL\
THLdFNk|Nc|\
:8K"; main (
int C,char** A) {for(x=A[1],i=calloc(strlen(x)+2,163840);
C-1;C<3?Q=_= 0,(z[1]=*x++)?((*x++==104?z[1]^=32:--x), X =
strstr(Z,z)) &&(X+=C++):(printf("P2 %d 320 4 ",V=b/2+32),
V*=2,s=Q=0,C =4):C<4?Q-->0?i[(int)((l+=o)+b)][(int)(k+=B)
]=1:_?_-=.5/ 256,o=(v(2)-(l=v(0)))/(Q=16),B=(v(3)-(k=v(1)
))/Q:*X>60?y ,q(L[4],L[5])q(L[6],L[7])*X-61||(++X,y,y,y),
Y:*X>57?++X, y,Y:*X >54?++X,b+=*X++%64*4:--C:printf("%d "
,i[Q][s]+i[Q ][s+1]+i[Q+1][s]+i[Q+1][s+1])&&(Q+=2)
This program accepts ASCII formatted mazes as input, and renders them onscreen for the user to explore, complete with Line Of Sight - you cannot see parts of the maze your avatar could not have seen.
#include /*****************************************************/
int m[256 ] [ 256 ],a
,b ;;; ;;; WINDOW*w; char*l="" "\176qxl" "q" "q" "k" "w\
xm" "x" "t" "j" "v" "u" "n" ,Q[
]= "Z" "pt!ftd`" "qdc!`eu" "dq!$c!nnwf"/** *** */"t\040\t";c(
int u , int v){ v?m [u] [v-
1] |=2,m[u][v-1] & 48?W][v-1 ] & 15]]):0:0;u?m[u -1][v]|=1 ,m[
u- 1][ v]& 48? W-1 ][v ]&
15] ]):0:0;v< 255 ?m[ u][v+1]|=8,m[u][v+1]& 48? W][ v+1]&15]]
):0 :0; u < 255 ?m[ u+1 ][v ]|=
4,m[u+1][ v]&48?W+1][v]&15]]):0:0;W][ v]& 15] ]);}cu(char*q){ return
*q ?cu (q+ 1)& 1?q [0] ++:
q[0 ]-- :1; }d( int u , int/**/v, int/**/x, int y){ int
Y=y -v, X=x -u; int S,s ;Y< 0?Y =-Y ,s,
s=- 1:( s=1);X<0?X=-X,S =-1 :(S= 1); Y<<= 1;X<<=1; if(X>Y){
int f=Y -(X >>1 );; while(u!= x){
f>= 0?v+=s,f-=X:0;u +=S ;f+= Y;m[u][v]|=32;mvwaddch(w,v ,u, m[u
][ v]& 64? 60: 46) ;if (m[ u][
v]&16){c(u,v);; ;;; ;;; return;}} }else{int f=X -(Y>>1);; while
(v !=y ){f >=0 ?u +=S, f-= Y:0
;v +=s ;f+=X;m[u][v]|= 32;mvwaddch(w,v ,u,m[u][v]&64?60:46);if(m[u
][ v]& 16) {c( u,v );
; return;;;}}}}Z( int/**/a, int b){ }e( int/**/y,int/**/ x){
int i ; for (i= a;i <=a
+S;i++)d(y,x,i,b),d(y,x,i,b+L);for(i=b;i<=b+L;i++)d(y,x,a,i),d(y,x,a+ S,i
); ;;; ;;; ;;; ;;; ;
mvwaddch(w,x,y,64); ;;; ;;; ;;; prefresh( w,b,a,0,0 ,L- 1,S-1
);} main( int V , char *C[
] ){FILE*f= fopen(V==1?"arachnid.c"/**/ :C[ 1],"r");int/**/x,y,c,
v=0 ;;; initscr (); Z(Z (raw
() ,Z( curs_set(0),Z(1 ,noecho()))),keypad( stdscr,TRUE));w =newpad
( 300, 300 ) ; for (x= 255 ; x >=0 ;x--
) for (y= 255 ;y>=0;y-- )m[ x][ y]= 0;x=y=0;refresh( );while
( (c= fgetc (f) )+1) {if(
0||c==10|| x== 256){x=0;y++;if(y==256 )break;;} else{m[x][y]=(c ==
'~' ?64 : c ==32 ?0: 16) ;;x ++;
}}for(x=0 ;x< 256;x++)m [x][0]=16 ,m[ x][ 255]=16;for(y=0
;y< 256 ; y ++) m[0 ][y ] = 16,
m[255][y] =16 ;a=b=c=0; x=y =1; do{v++;mvwaddch (w, y,x ,m[
x][ y]& 32? m[x ][y ] & 16?
0| acs_map[l[m[x][y]&15]]:46 : 32);c==0163&&!(m[x][y+1]&16)?y++: 0;c
== 119 &&! (m[ x][
y- 1]& 16) ?y--:0;;c ==97 &&!(m[x-1][y]&16)?x--:0;c==100&&!(m[x+1
][ y]& 16) ? x ++:0 ;if( c==
3- 1+1 ){endwin( );; return(0) ;}x -a<5?a>S- 5?a-=S-5:(a=0):
0;x -a> S-5?a<255 -S* 2?a +=S
-5:(a=256-S):0; y-b<5?b>L-5?b-=L-5:(b =0) :0; y-b>L-5?b<255-L *2?
b+= L-5 :(b =256
-L) :0;e(x,y);if(m[x][y]&64)break;}while((c=getch())!=-1);endwin();cu(Q);
printf(Q,v);}
Rinia is a tool for embedding CRCs in text files. Rinia will insert a human-readable checksum string in the text itself! ^_^
/* ,*/
#include
#include/* _ ,o*/
#define c(C)/* - . */return ( C); /* 2004*/
#include /*. Moekan "' `\b-' */
typedef/* */char p;p* u ,w [9
][128] ,*v;typedef int _;_ R,i,N,I,A ,m,o,e
[9], a[256],k [9], n[ 256];FILE*f ;_ x (_ K,_ r
,_ q){; for(; r< q ; K =((
0xffffff) &(K>>8))^ n[255 & ( K
^u[0 + r ++ ] )]);c (K
)} _ E (p*r, p*q ){ c( f =
fopen (r ,q))}_ B(_ q){c( fseek (f, 0
,q))}_ D(){c( fclose(f ))}_ C( p *q){c( 0- puts(q ) )}_/* /
*/main(_ t,p**z){if(t<4)c( C("" "\40 "
/*b9213272*/"" ) )u=0;i=I=(E(z[1],"rb")) ?B(2)?0 : (((o =ftell
(f))>=8)?(u =(p*)malloc(o))?B(0)?0:!fread(u,o,1,f):0:0)?0: D():0 ;if(
!u)c(C(" bad\40input "));if(E(z[2],"rb" )){for(N=-1;256> i;n[i++] =-1 )a[
i]=0; for(i=I=0; i-1;i++)++a[R] ?(R==N)?( ++I>7)?(n[
N]+1 )?0:(n [N ]=i-7):0: (N=R) |(I=1):0;A =-1;N=o+1;for(i=33;i<127;i++
)( n[i ]+ 1&&N>a[i])? N= a [A=i] :0;B(i=I=0);if(A+1)for(N=n[A];
I< 8&& (R =fgetc(f ))> -1&& i N+7)?(R==A)?((*w[I
] =u [i])?1:(*w[I]= 46))?(a [I++]=i):0:0:0;D();}if(I<1)c(C(
" bad\40la" "yout "))for(i =0;256>(R= i);n[i++]=R)for(A=8;
A >0;A --) R = ( (R&1)==0) ?(unsigned int)R>>(01):((unsigned
/*kero Q' ,KSS */)R>> 1)^ 0xedb88320;m=a[I-1];a[I
]=(m R;R++)if(R-47&&R-92
&& R-(_)* w[i])*( v++)= (p)R;*v=0;}for(sprintf
/*'_ G*/ (*w+1, "%0" "8x",x(R=time(i=0),m,o)^~
0) ;i< 8;++ i)u [N+ i]=*(*w+i+1);for(*k=x(~
0,i=0 ,*a);i>- 1; ){for (A=i;A-1?!w[i][++ e[+ i]]:0;
) for( A=+i--; A
This is a configurable banner-like program : Convert a character glyph into a data file, or print a string using glyphs from a data file. Extra functionality: The program can also act as a Morse encoder, unarguably.
#include
#include
#include
#include
#define t(x) typedef x
#define G return
#define Y(x) x;x
#define e(s) exit(s);
#define b(x,o) x o x
#define Z while
#define y fclose
#define end static
t(signed)char U;t(struct) b(O,);
t( U*)
H; t(O
*) *o;
struct O{ O* l, **h; void* L; } ; t(int)i; i P(U g) { G
isspace(g); } H D(H s){H p,r;if(!s)G 0;for(p=(H)s;*p &&
!P(*p); p++); if(r=malloc(p-s))for(p=r; *s&&! P(*s);p++
,s++)b(*,p=) s; G r;} void l(o p,O*x){*(o)x=* p; *p=x;}
#define m(x) do{ if(!(q = malloc(sizeof(O)))) e(1)q->l\
=0 ;q\
-> L=\
x ; } while (0)
i(*R)(i) =putchar;i h(
o f,H d,U c){O*q; f+=c;Z(d&&*d)
{ m(D(d)); l(f++, q); Z(*d && !P(*d
)) d++; Z(*d && P(*d)) d++; } G b(,0);}
void k() { static U b(c,;) ?R(c):(c='\n'); }
i main (i Q, H *l){static o
X;i t,j; switch (Q
){ case 1: { H
*p, I [] ={
"aH" " "
"B" "0"
" " "B"
"" "B"
"" " "
"B" ","
" " ","
" `" "0 "
"b0 " "@, "
"0 Hb," " B2 "
"H0 b, B b" "H HB b`, "
"H, @ 2 `, " "@2 H2 BH Bb"
" b@","AH B0 BB B, , `0 b0 @, 0 Hb, B2 H0"
" b, B bH HB b`, H, @ 2 `, @2 H2 BH Bb"
" b@","0bHb, HbH `H2 @b, @H @0 B@ "
"b@ bH0 bHB",".HHH","?`H0",
",b@b,"," +", 0}; p=I;
if (!(X=calloc(
6<<6,sizeof(O*))))e(1)
do{h(X,(*p)+1,**p);} Z(*(++p));
D: if ((t = getchar()) >= 0) { k();
goto u;}e(0)}case 2:{U *p,e[33]; b(i, )
,w;for(i=0;i<34;i++)i[e]=b(0,;w=);p=e; Z(1){
t = (w == 200) ? 10:getchar();
switch(t) { case 0xa:
case EOF: if(w--
){R(1[l ][0])
;for(i =0,
p=e;i <=w
;i+= 6){
R ( *p+
'+' );*
p++ =0;
;} R(
0xa );w
=-1 ;}p=
e- 1;case
32: if (t<0) e(
0) break; /*/*
/*/ default : *
p
|=(001<<(w%6));
}if((++w%6)==0)p++;}e(
0)}case 3:{O*u,*q,*x;U s[0400];
i i;FILE*F; j:j=1;if(!(X=calloc(6<<
6,sizeof(O*)))) e(1) if(!(F=fopen(j[l],
"r")))e(1)Z(fgets(s,j<<8,F))(*s)&&h(X,s+j,*s
);j=b(i,=)&0xff; i:u=0;x=X[i];
Z(x){q=Y(*( o)x)=Y(u)
=Y(x)=q;} i[X]=u
;i=(i-2 +9)%(
sizeof (s))
;if(i ^j)
goto i;;
y(F) ; }
case 4:{
end i i
;if (!
X){ i=j
=1; goto
j;} if(i){O
**x ,*m=*(x=X);
do* x=1[x];Z(++
xL;Z(*p>=n){i=(*p++)-n;for(c=0;c<6;c++,i=i
>>1){ if(b(!, i &&)(*p >= n))
break;R(32+ (i&1)*3);
}}R(10);a =a->l;
}if(Q<2 )goto
D;if(* l[2
]){R( 10)
;main (4,
l); }}}
Z(Q ++<
1){ X+=
t; if
((t &7)
>3) goto
i; else {
t-- ;putchar(t)
;t =(t&7)?t:t-
'*' ;}}exit(0);
}
Je suis définitivement fan.