A few small obfuscated Programs


This little C programs print themself.
main(){char*p="main(){char*p=%c%s%c;(void)printf(p,34,p,34,10);}%c";(void)printf(p,34,p,34,10);}
main(a){a="main(a){a=%c%s%c;printf(a,34,a,34);}";printf(a,34,a,34);}
main(){char*a="main(){char*a=%c%s%c;int b='%c';printf(a,b,a,b,b);}";int b='"';printf(a,b,a,b,b);}
main(a){printf(a,34,a="main(a){printf(a,34,a=%c%s%c,34);}",34);}
(
download)


This C program prints the prim numbers between 2 and 100.
#define oO(o) for (o=2; o
#define Oo(o) ; o++)
#define OO(O,o) if (O==o)
#define oo(o,O) oO(o) O Oo(o)
int main() { int o,O; oo(o,<100)
oo(O,<=o) OO(o,O) printf("%d ",o);
else OO(o%O,0) break; putchar('\n'); return 0; }
(
download)


This Perl program prints prim numbers.
perl -wle '$_ = 1; (1 x $_) !~ /^(11+)\1+$/ && print while $_++'
(
download)


The following is a Python RSA implementation.
from sys import*;from string import*;a=argv;[s,p,q]=filter(lambda x:x[:1]!=
'-',a);d='-d'in a;e,n=atol(p,16),atol(q,16);l=(len(q)+1)/2;o,inb=l-d,l-1+d
while s:s=stdin.read(inb);s and map(stdout.write,map(lambda i,b=pow(reduce(
lambda x,y:(x<<8L)+y,map(ord,s)),e,n):chr(b>>8*i&255),range(o-1,-1,-1)))
(
download)


You won't beleve what this program does ...
#include <stdio.h>
main(t,_,a) char *a; { return!0<t?t<3?main(-79,-13,a+main(-87,1-_,
main(-86,0,a+1)+a)):1,t<_?main(t+1,_,a):3,main(-94,-27+t,a)&&t==2?_<13?
main(2,_+1,"%s %d %d\n"):9:16:t<0?t<-72?main(_,t,
"@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l+,/n{n+,/+#n+,/#\
;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l \
q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# \
){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' \
iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c \
;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n' ')#\
}'+}##(!!/"):t<-50?_==*a?putchar(31[a]):main(-65,_,a+1):
main((*a=='/')+t,_,a+1):0<t?main(2,2,"%s"):*a=='/'||main(0,main(-61,*a,
"!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry"),a+1); }
(
download)


This perl code prints out a Larry Wall quote.
@a=(Lbzjoftt,Inqbujfodf, Hvcsjt); $b="Lbssz Wbmm"
;$b =~ y/b-z/a-z/ ; $c = " Tif ". @a ." hsfbu wj"
."suvft pg b qsphsbnnfs" . ":\n";$c =~y/b-y/a-z/;
print"\n\n$c ";for($i=0; $i<@a; $i++) { $a[$i] =~
y/b-y/a-z/;if($a[$i]eq$a [-1]){print"and $a[$i]."
;}else{ print"$a[$i], "; }}print"\n\t\t--$b\n\n";
(
download)


More obfuscated C code ..
#include <stdio.h>
int main(int i,char**a){if(i==1){a[0]="\v!!Tr`fd;!=qsnf,o`ld?!=qnrhuhwd,houd"
"fds,otlcds?\v\v!!Vshuudo!cx!Bmhggnse!Vnmg!,!vvv/bmhggnse/`u\v\v";main(8,a);
return 1;}else if(i==2){a[0]="Uid!qshl!g`bunsr!ng!";main(8,a);printf("%s",
a[1]);a[0]="!`sd;";main(8,a);for(i=2;i<=atoi(a[1]);i++)main(-i,a);a[0]="\v";
main(8,a);}else if(i==8)for(i=0;a[0][i];i++)putchar(a[0][i]^1);else if(i>=9){
a[0]=a[1];i-=9;while(*(a[0]+1))a[0]++;while(a[0]>=a[1]){*(a[0]--)='0'+i%10;
i/=10;}}else{i*=-1;while(atoi(a[1])%i==0){main(9+atoi(a[1])/i,a);a[0]="!";
main(8,a);printf("%d",i);}}return 0;}
(
download)

#include <stdio.h>
int main(_,__,x)char*__;{if(!_)while(__[_++])putchar(__[_-1]^1);
else if(_>1){main(0,__);x+=main(0,x);_>2?main(_-1,__,x):main(0,
"\v!!I`wd!Gto \v\v");}else main(4,"\v!!SNBJ!Mhoty!Stmd{!",
"Une`x/\v\0Unlnssnv/\v\0Dwds/\v"); return _;}
(
download)


I won the LUGA Perl contest with the following program.
#!/usr/bin/perl
$|=1;@_=split//,"Lhnvx\%Utes Drjuw \@uptwif";for(0..$#_){
join("",splice(@_,0,$_+1))=~/(.*)/;print"\r$1";splice@_
,0,0,split(//,$1);print$_[$_]=chr(ord($_[$_])^($_%8))while
++$_<=$#_;select(undef,undef,undef,0.25);}print"\n";
(
download)