Jump to content
xisto Community
sourabhj

A Crazy Program In C Dont know how it works

Recommended Posts

Its a code iam sharing i found while reading about c, its a code from a winner of world most obsfucated code contest just have a look the output of the program is after the code

#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);}


Output of the program
*****************************************************************************													 Output  Start Here*********************************************************************************On the first day of Christmas my true love gave to mea partridge in a pear tree.On the second day of Christmas my true love gave to metwo turtle dovesand a partridge in a pear tree.On the third day of Christmas my true love gave to methree french hens, two turtle dovesand a partridge in a pear tree.On the fourth day of Christmas my true love gave to mefour calling birds, three french hens, two turtle dovesand a partridge in a pear tree.On the fifth day of Christmas my true love gave to mefive gold rings;four calling birds, three french hens, two turtle dovesand a partridge in a pear tree.On the sixth day of Christmas my true love gave to mesix geese a-laying, five gold rings;four calling birds, three french hens, two turtle dovesand a partridge in a pear tree.On the seventh day of Christmas my true love gave to meseven swans a-swimming,six geese a-laying, five gold rings;four calling birds, three french hens, two turtle dovesand a partridge in a pear tree.On the eighth day of Christmas my true love gave to meeight maids a-milking, seven swans a-swimming,six geese a-laying, five gold rings;four calling birds, three french hens, two turtle dovesand a partridge in a pear tree.On the ninth day of Christmas my true love gave to menine ladies dancing, eight maids a-milking, seven swans a-swimming,six geese a-laying, five gold rings;four calling birds, three french hens, two turtle dovesand a partridge in a pear tree.On the tenth day of Christmas my true love gave to meten lords a-leaping,nine ladies dancing, eight maids a-milking, seven swans a-swimming,six geese a-laying, five gold rings;four calling birds, three french hens, two turtle dovesand a partridge in a pear tree.On the eleventh day of Christmas my true love gave to meeleven pipers piping, ten lords a-leaping,nine ladies dancing, eight maids a-milking, seven swans a-swimming,six geese a-laying, five gold rings;four calling birds, three french hens, two turtle dovesand a partridge in a pear tree.On the twelfth day of Christmas my true love gave to metwelve drummers drumming, eleven pipers piping, ten lords a-leaping,nine ladies dancing, eight maids a-milking, seven swans a-swimming,six geese a-laying, five gold rings;four calling birds, three french hens, two turtle dovesand a partridge in a pear tree.****************************************************************************										   Output ends****************************************************************************
Its a cool program what if this technique can be used to compress file make a program to create a c code for a file to be compressed it will then be compiled to exe when run produces the large file

Share this post


Link to post
Share on other sites

try this.... u will be astonished!

#include <stdio.h>main(){  int c;				/* Character read from the file.	*/  FILE *ptr;			/* Pointer to the file. FILE is a				   structure  defined in <stdio.h>	*/				/* Open the file - no error checking done */  ptr = fopen("/etc/hosts","r");				/* Read one character at a time, checking 				   for the End of File. EOF is defined 				   in <stdio.h>  as -1 			*/  while ((c = fgetc(ptr)) != EOF)  {    printf("%c",c);		/* O/P the character to the screen	*/  }  fclose(ptr);			/* Close the file.			*/

Edited by nirmal_1288 (see edit history)

Share this post


Link to post
Share on other sites

wow! that code from a winner of world most obsfucated code contest was very great! I dont know how will i say it but if you'll ask me to rate it... hmmm 10/10! That's really amazing! :P wish i could make something like that someday! hehe!

Share this post


Link to post
Share on other sites

will i have seen allot of string cod but this is very hard fo me to read i didnot think that you can actly rot sutch code in ci thout only bash of perel scrips can be like thati know that you can make sutch cod in bash but doing it in c no wayi cant even count how meny if then else in that codebut i know that he use it like thisA?B:Cif (A) then (:rolleyes:else ©and so on

Share this post


Link to post
Share on other sites

Wow. I can't even read that.I see the return function, but does it just call for the strings from the header file or does it actually loop, repeating the first verse and inserting variables and the second verse appropriate verse? I see conditionals, but I don't see an actual loop... it's pretty confusing.My C skills are beyond elementary... so maybe I'm just missing something here. :)

Share this post


Link to post
Share on other sites

Its a code iam sharing i found while reading about c, its a code from a winner of world most obsfucated code contest just have a look the output of the program is after the code
CODE
#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);}



Output of the program

CODE
*****************************************************************************
Output Start Here
********************************************************************************
*
On the first day of Christmas my true love gave to me
a partridge in a pear tree.

On the second day of Christmas my true love gave to me
two turtle doves
and a partridge in a pear tree.

On the third day of Christmas my true love gave to me
three french hens, two turtle doves
and a partridge in a pear tree.

On the fourth day of Christmas my true love gave to me
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

On the fifth day of Christmas my true love gave to me
five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

On the sixth day of Christmas my true love gave to me
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

On the seventh day of Christmas my true love gave to me
seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

On the eighth day of Christmas my true love gave to me
eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

On the ninth day of Christmas my true love gave to me
nine ladies dancing, eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

On the tenth day of Christmas my true love gave to me
ten lords a-leaping,
nine ladies dancing, eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

On the eleventh day of Christmas my true love gave to me
eleven pipers piping, ten lords a-leaping,
nine ladies dancing, eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

On the twelfth day of Christmas my true love gave to me
twelve drummers drumming, eleven pipers piping, ten lords a-leaping,
nine ladies dancing, eight maids a-milking, seven swans a-swimming,
six geese a-laying, five gold rings;
four calling birds, three french hens, two turtle doves
and a partridge in a pear tree.

****************************************************************************
Output ends
****************************************************************************

Its a cool program what if this technique can be used to compress file make a program to create a c code for a file to be compressed it will then be compiled to exe when run produces the large file


Did anyone try to compile this ? because it doesnt compile for me. besides it has some syntax errors like where is the '{' after the main fuction.

Share this post


Link to post
Share on other sites

I tried to read it, and I failed.Tried to compiled it, and I failedThis is what I got.Does anyone have an Idea on how to compile this?source.cpp(3) : error C2065: 't' : undeclared identifiersource.cpp(3) : error C2065: '_' : undeclared identifiersource.cpp(3) : error C2065: 'a' : undeclared identifiersource.cpp(4) : error C2448: 'main' : function-style initializer appears to be a function definitionalot of bad spacing in the program, should be a line after each ";"

Share this post


Link to post
Share on other sites

OMG. Who's this guy? The owner of C or something? I need to try this code. If you are getting errors, maybe your source of the article made some mistakes :) And that code is harder to read than assembly =/Did you try to search google this?Greetz~Jo?o Lopes

Share this post


Link to post
Share on other sites

I tried to read it, and I failed.Tried to compiled it, and I failed
This is what I got.
Does anyone have an Idea on how to compile this?

source.cpp(3) : error C2065: 't' : undeclared identifier
source.cpp(3) : error C2065: '_' : undeclared identifier
source.cpp(3) : error C2065: 'a' : undeclared identifier
source.cpp(4) : error C2448: 'main' : function-style initializer appears to be a function definition

alot of bad spacing in the program, should be a line after each ";"


if you put a var type in front of t and _ and a so that it looks like this for example main(char t,char _,char a) then you will get the syntax error complaining about the missing '{' along with some other errors

In my opinion this program doesn't work, it was either never ment to work or is missing some chunk of it. i dunno

Share this post


Link to post
Share on other sites

Did anyone try to compile this ? because it doesnt compile for me. besides it has some syntax errors like where is the '{' after the main fuction.

I just did, using Borland C++ and command-line compiler, without changing a iota in the source code (cut and paste).
There were a few warnings like:

Warning C:\tmp\obfusca.c 6: Call to function 'main' with no prototype in function main
Warning C:\tmp\obfusca.c 6: Call to function 'main' with no prototype in function main
Warning C:\tmp\obfusca.c 6: Call to function 'main' with no prototype in function main
Warning C:\tmp\obfusca.c 6: Call to function 'main' with no prototype in function main
Warning C:\tmp\obfusca.c 7: Call to function 'main' with no prototype in function main
Warning C:\tmp\obfusca.c 7: Call to function 'main' with no prototype in function main
Warning C:\tmp\obfusca.c 14: Call to function 'main' with no prototype in function main
Warning C:\tmp\obfusca.c 15: Call to function 'main' with no prototype in function main
Warning C:\tmp\obfusca.c 16: Call to function 'main' with no prototype in function main
Warning C:\tmp\obfusca.c 16: Call to function 'main' with no prototype in function main
Warning C:\tmp\obfusca.c 17: Call to function 'main' with no prototype in function main
Warning C:\tmp\obfusca.c 17: Call to function 'main' with no prototype in function main
Turbo Link Version 1.50 for Win32 Copyright © 1993,1994 Borland International

and executable code produced exactly the output as claimed!

Truly amazing and mind-boggling.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.