Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 The Amazing Obfuscated C
Index -> Programming, C++ -> C++ Tutorials
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
rizzix




PostPosted: Thu Jan 13, 2005 10:07 pm   Post subject: The Amazing Obfuscated C

I found this on some site.. I'm sure some of you might have seen it before. The code below is just unbelievable! Run it and watch it print out the entire "Twelve days of Christmas!" song for you!. I challenge anyone to give me a clear and concise explainiation for the code (ha! if u can):

c:
#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;# ){n\
l]!/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(a[31]):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);}
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Thu Jan 13, 2005 10:26 pm   Post subject: (No subject)

It relies on the fact that C doesn't have much of a type system at all.

This is why Pascal and its derivativesare still popular, along with very strongly-typed functional languages. Smile
md




PostPosted: Thu Jan 13, 2005 11:31 pm   Post subject: (No subject)

In fact if you merged the class features of C++ (and the +=, etc operators...) and pascal it would make an awsome language.
StarGateSG-1




PostPosted: Wed Feb 09, 2005 12:30 pm   Post subject: Duh!!

Common that is easy to make sense of...

All it does is use char variables and alter them to say what is says.

I don't even have to know C to know that!!
StarGateSG-1




PostPosted: Wed Feb 09, 2005 12:30 pm   Post subject: Duh!!

Common that is easy to make sense of...

All it does is use char variables and alter them to say what is says.

I don't even have to know C to know that!!
McKenzie




PostPosted: Wed Feb 09, 2005 1:09 pm   Post subject: (No subject)

That doesn't explain any of the finer points.

I don't plan to take the whole thing apart myself but it doesn't seem to be abusing the C type system. The most obvious thing that was done was the killing of all white space. The next big thing is that it is recursively calling main and using the first spot (argc, argv, ??? <- what's the third parameter?) to decide how the function will act. The code uses the messy conditional operator <cond>?<val 1>:<val 2> to do all of it's branching. I'll never understand why Java preserved that syntax. It's a fairly safe assumption that the characters are buried in those strings (probably shifted by some value)
wtd




PostPosted: Wed Feb 09, 2005 3:52 pm   Post subject: (No subject)

McKenzie wrote:
I'll never understand why Java preserved that syntax.


Because Java for some odd reason preserves the procedural idea of conditional statements, rather than expressions.

In something like Haskell (though the syntax is only off by an "end" for Ruby), for example:

code:
foo = if 1 < 2 then "hello" else "world


You have in Java, either:

code:
if (1 < 2) {
   foo = "hello";
} else {
   foo = "world";
}


Or:

code:
foo = 1 < 2 ? "hello" : "world";


Which of the two is more palatable?

Essentially it's syntax which compensates for a failing in an already existing portion of the language. It's a kludge.
Catalyst




PostPosted: Thu Feb 10, 2005 12:35 am   Post subject: (No subject)

this has got to be mentioned too.
say hello to tetris :

c++:
#include                                                               <ddraw.h>
#define B(x,y,r,p) (p&1<<(((x^(r+1&2?3:0))<<(r*2&2))+((y^(r&2?3:0))*(r&1?1:4))))
#define F(x,y,w,h,c) {RECT R={x,y,x+w,y+h};b.dwFillColor=c;_->Blt(&R,0,0,k,&b);}
char *m="Tetris\0By Pouya Larjani\0Score:\0Next:\0GAME OVER",z[9]; unsigned L=16
,k=16778240,Q=9,I,x=9,n,y,r,p,i,a,t,u,v,e,s[30][20],P[]={1632,75328,83488,74274,
222272,221728,206368};DDBLTFX b={100};LPDIRECTDRAW d;LPDIRECTDRAWSURFACE V,_;HDC
q;HWND W;LOGFONT l={96,48};MSG g;DDSURFACEDESC S={108,33,0,0,0,1,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0,0,0,{536}};HFONT f=CreateFontIndirect(&l);DDSCAPS c={4};X()
{for(i=1;i<30;i++){a=1;for(I=0;I<20&&a;a=s[i][I++]);if(a){for(I=i*20+19;I>=20;s[
I/20][I%20]=s[I/20-1][I--%20]);e++;return 1;}}return 0;}M(int p){return(++p<<21&
1<<23|p<<14&1<<15|p<<7&1<<7)+8355711;}K(int v){return GetAsyncKeyState(v)&32768;
}O(int x,int y,int r,int p){for(I=0;I<L;I++)if(B(I%4,I/4,r,P[p])&&(x+I%4<0||x+I%
4>19||y+I/4<0||y+I/4>29||s[y+I/4][x+I%4]))return 0;return 1;}void G(){v=r;t=x;u=
y;TranslateMessage(&g);DispatchMessage(&g);(g.message==275&&Q)?SetTimer(W,1,1050
-50*((e<100)?e/5:20),0),u++:K(38)?v=r?v-1 : P[p]>>16&3:K(37)?t--:K(39)?t++:K(40)?u
++:K(27)?PostQuitMessage(0):0;if(O(t,u,v,p))x=t,y=u,r=v;else if(u-y){for(I=0;I<L
;I++)if(B(I%4,I/4,r,P[p]))s[y+I/4][x+I%4]=1<<23;y?p=n,y=0,n=rand()%7,x=9,r=0:Q=0
;while(X());}}void R(){F(0,0,640,480,1<<15);for(I=0;I<600;I++)F(I%20*L,I/20*L,L,
L,s[I/20][I%20]);for(I=0;I<L;I++){if(B(I%4,I/4,r,P[p]))F((x+I%4)*L,(y+I/4)*L,L,L
,M(p));F(336+I%4*L,400+I/4*L,L,L,B(I%4,I/4,0,P[n])?M(n):0);}_->GetDC(&q);itoa(e,
z,10);SelectObject(q,GetStockObject(13));SetTextColor(q,M(6));SetBkMode(q,0);V->
Restore();TextOut(q,336,120,m+7,L);TextOut(q,336,340,m+24,6);TextOut(q,408,340,z
,strlen(z));TextOut(q,336,380,m+31,5);TextOut(q,444,300,m+37,9-Q);SelectObject(q
,f);TextOut(q,336,20,m,6);_->ReleaseDC(q);V->Flip(0,1);}WINAPI WinMain(HINSTANCE
h,HINSTANCE,char*,int){srand(timeGetTime());WNDCLASS w={0,DefWindowProc,0,0,h,0,
0,0,0,m};RegisterClass(&w);W=CreateWindow(m,m,2432696320,0,0,640,480,0,0,h,0);p=
rand()%7;ShowCursor(0);DirectDrawCreate(0,&d,0);d->SetCooperativeLevel(W,83);d->
SetDisplayMode(640,480,32);d->CreateSurface(&S,&V,0);V->GetAttachedSurface(&c,&_
);n=rand()%7;SetTimer(W,1,0,0);while(g.message!=18)PeekMessage(&g,0,0,0,1)?G():R
();int U=0;V->Release();d->Release();DestroyWindow(W);DeleteObject(f);return U;}



i dont even want to know what that person was thinking Laughing
Sponsor
Sponsor
Sponsor
sponsor
md




PostPosted: Thu Feb 10, 2005 9:07 pm   Post subject: (No subject)

I think it might have been "woah this is good crack!"
rizzix




PostPosted: Thu Feb 10, 2005 9:15 pm   Post subject: (No subject)

that code dosen't compile Confused
Display posts from previous:   
   Index -> Programming, C++ -> C++ Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: