Obfuscated Code

from time to time I amuse myself by writing little pieces of obfuscated code. it's not worthy of competition in an obfuscated code contest, but it's still fun. since they're all pretty small pieces of code, i've just pasted them right into this page. I encourage you to try to figure out what they do without reading my comments on them (which of course preceed them) or compiling them. But only if you enjoy torturing yourself in that manner.

a signature piece

I wrote this sometime during the fall of 1999, it just prints out my name and email address. it recursively calls itself in order to do so, using a static char* array that gets incremented every pass through the main function. this doesn't compile with c++ compilers because in c++ it is apparently illegal to recursively call main.

int main(int i){static char *p="\n=eok)bmgi[\\gX2d[YW_\\'\n\\SQO7\004HVF0"; char c;if(i<-33)return i+1;else{c=((i>0)?i[--p-i+1]:*(p++)); putchar(main(i-1)-((i>0)?0:i));return c;}}

a non-signature piece

I wrote this sometime in early february, 2000. although this code prints out my name and email address as usual, it is unsuitable as a signature, due to it's size. the size is bloated because you can only put one #define on a line, so since it was long but with lots of whitespace, i filled it up with bogus comment blocks. this one indexes into an array containing the encoded output string via another array of characters. It also contains no spaces other than ones within strings.

/**//**//**/#define/**/_S_/**/}/*(C)2000*//**/ /**//**//**//**//**//**//**//**//**/#define/**/_K_/**/putchar('2'-'('); #define/**/_I_/**/putchar(_3[_2[_5]-*(_2+4)]-((_2[_5]-60)%10));_l(_0); /**//**/#define/**/_R_/**/int/**/_5,_;for(_5=0;_5<5;_5++)/**//**//**/ #define/**/_0_/**/"\"""r"/**/"e""e""f""e"/**/"r""-""""m""a"/**/"n\""" """ #define/**/_4_/**/int/**/main(int/**/_0){static/**/char/**/*_2="CJLJ<"; #define/**/_J_/**/for/**/(_5=0;_5<27;_5++){_=_4[_5]-'F';putchar(_3[_]-_%10);} #define/**/_2_/**/static/**/char/**/*_3=" S>AnnqWx{@/irixzo";/**//**/ void/**/_l(int/**/_){switch(_){case/**/1:return;break;}printf(_0_);}/**/ _4_/**/_2_/**/static/**/char/**/*_4="GKJLUFHNOKJLUPTURTOSVWQSORI";/**/ /**//**//**//**//**/_R_/**/_I_/**/_J_/**/_K_/**/_S_/**//**//**//**//**/

a signature piece

this one was written sometime in mid february 2000. it prints out, depending on the number of command line arguments, my name and email address, my webpage url, or gibberish. it accomplishes this thru a very simplistic pseudo-random number generator that is seeded using argc.

char *s=":r\0tfnq<=-foiha\xA/,,aerrmprrr\x1D\x9heefph;cfqife\x1Dtsnhjq-QpM" "nmnn\0bidqf";unsigned int _(unsigned int _0){return((337*_0+113)%63);}int main(int a){unsigned int b=_(a);while(b[s]){putchar(s[b]+b%(a+2));b=_(b);}}

fun with ascii

this one was written early october 2000. it draws a box with a '*' bouncing around inside it.

void s(int*_,int __){*_=(__<=0)?((*_<0)?-*_:*_):((*_>0)?-*_:*_);}unsigned int k;void r(int*_){*_=(k=(16807*k)%2147483647)%5-2;}void _(int c,int n){for(;n>0; --n)putchar(c);}int main(int a){int p[2]={(a+7)%19,(a+12)%19},d[2]={a%5-2,(a+2) %5-2},m,n;k=a;_(8,2048);_(32,2048);_(8,2048);while(1){_(32,1);_(45,19);_(32,1); _(10,1);for(m=0;m<19;++m){_(124,1);for(n=0;n<19;++n){if(p[0]==n&&p[1]==m)_(42, 1);else _(32,1);}_(124,1);_(10,1);}_(32,1);_(45,19);_(32,1);for(m=0;m<2;++m){ if(p[m]<=0||p[m]>=18){s(d+m,m[p]);r(d+1-m);}}for(n=0;n<2;++n){p[n]+=d[n];if (p[n]<0)p[n]=0;if(p[n]>18)p[n]=19;}_(8,2048);_(0,98765);}return 0;}

fun with noise

this one was written may 4 2000. it generates a xpm file, according to simple command line specifications, filled with "patterned" "random" noise. (the xpm data is printed to stdout, redirect to a file, then view said file with your favorite graphics app)

int rs;int U=50,V=50,S=50,P=2;int r(){return(rs=(rs*6197)%100001);} char *_S_ = "/+\"[TR&17\023}\177m" "\201wr0tzt\2065@7\210\220\214\215\213\225y|" "@^B\236."; void _(int i){putchar(i);}void _n(int i){_(i/10+'0');_(i%10+'0'); }void _h(int i){ _((i>9)?(i+55):(48+i));}void _b(){_('\t');_('c');_(' '); _('#');}void _e(){_(34);_(',');_('\n');}void m(){int H, Z_32, q, Z;for(q = 0; q<37;++q)_(q[_S_]-q);_(34);_n(V);_(' ');_n(U);_(' ');_n(S);_(' ');_n(P);_(34); _(',');_('\n');for(H=0;H<25;++H){if(P==1){if(H>=S)goto ______;_(34);_('a'+H); _b();_h(r()%16);_h(r()%16);_h(H%16);_h(r()%16);_h((H*r())%16);_h(r()%16);_e(); }else{for(Z_32=0;Z_32<4;++Z_32){if(H*4+Z_32>=S)goto ______;_(34);_('a'+H); _('a'+Z_32);_b();_h(r()%16);_h(r()%16);_h(H%8+r()%8);_h(r()%16);_h(r()%16); _h(r()%16);_e();}}}______:for(H=0;H<U;++H){_(34);for(Z_32=0;Z_32<V;++Z_32){ if(P==1)_('a'+r()%S);else{do{q=r()%25;Z=r()%4;}while(q*4+Z>=S);_('a'+q); _('a'+Z);}}_e();}_('}');_(';');_('\n');}int main(int c, char* v[]){rs=((int) v[0])%6197;while(rs%2==0||rs%5==0)++rs;if(c>1)U=(v[1][0]-'0')*10;if(c>2)V=( v[2][0]-'0')*10;if(c>3){S=(v[3][0]-'0')*10;if(v[3][1])S+=(v[3][1]-'0');else S /=10;}if(S<25)P=1;m();return 0;/* by PWR ( */}


Created July 31, 2002 and updated later that day. Takes a command line argument for the height of the output.

; int main( int aa, char*v[]) {int x[5];0 [x]=aa>1?atoi (v[1]):017;for( 1[x]=1;1[x]<=0[x] ;++1[x]){for(3[x]=1 ;3[x]<0[x]-1[x]+1;++3 [x]){putchar(32);}for(2 [x]=0;2[x]<1[x];++2[x]){; ;putchar(46);putchar(32);}; putchar(10);}/**/return 0;};;