473,609 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how this program works

Hi,
FOllowing is a program which is written by someone else.
Its output is a wonderful poem. I dont understand how it works really.
can anyone tell.
thanks
cric

#include <stdio.h>
main(int t,char _,char *a)
{
return!0<t?t<3? main(-79,-13,a+main(-87,1-_,
main(-86, 0, a+1 )+a)):1,t<_?mai n(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'}{nlw b!/*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,{}:\nu wloca-O;m .vpbks,fxntdCeg hiry"),a+1);}
Nov 14 '05 #1
10 2005
Hehhehe, this is like an entry from an obfuscation
contest. Usually, there are some hints there.

BTW, I did a copy'n'paste into BC++ 5.02, and it
doesn't compile.

"free2cric" <fr*******@yaho o.com> wrote in message
news:e8******** *************** ***@posting.goo gle.com...
Hi,
FOllowing is a program which is written by someone else.
Its output is a wonderful poem. I dont understand how it works really.
can anyone tell.
thanks
cric

Nov 14 '05 #2

aurgathor wrote:
Hehhehe, this is like an entry from an obfuscation
contest. Usually, there are some hints there.

BTW, I did a copy'n'paste into BC++ 5.02, and it
doesn't compile.


GNU indent didn't like it neither.

I think it just isn't valid C code...

Tom

Nov 14 '05 #3

"Tom St Denis" <to********@gma il.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .

GNU indent didn't like it neither.

I think it just isn't valid C code...

Could be a code written for some old, pre-ansi
compiler. Of course, if the original poster was
able to compile and run this code, s/he should've
posted the compiler and instructions.
Nov 14 '05 #4
"Tom St Denis" <to********@gma il.com> wrote:
aurgathor wrote:
Hehhehe, this is like an entry from an obfuscation
contest. Usually, there are some hints there.

BTW, I did a copy'n'paste into BC++ 5.02, and it
doesn't compile.


GNU indent didn't like it neither.

I think it just isn't valid C code...


With a declaration like main(int t,char _,char *a)? I think it's safe to
say that it's nowhere near valid, let alone portable, C code.

Richard
Nov 14 '05 #5

free2cric wrote:
Hi,
FOllowing is a program which is written by someone else.
Its output is a wonderful poem. I dont understand how it works really. can anyone tell.
thanks
cric


Yes, I remeber this program. It is valid and it compiles fine with
GCC, even though it generates plenty of warnings. I *think* it works
by having a obscure string, do some operations on it to make it into
the lyrics, name it a obscure name, delete all the white space, print
the different substring of the string, and use recursion to print the
whole thing.

This program uses recursion to print one of the most famous Christmas
songs, "Twelve Days of Christmas".

The output of the program is:

"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
sevean 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 eig hth day of Christmas my true love gave to me
eight maids a-milking, sevean 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, sevean 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, sevean 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, sevean 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, sevean 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."

You have to admit, whoever wrote the program was pretty good.

Nov 14 '05 #6
Tom St Denis wrote:
aurgathor wrote:
Hehhehe, this is like an entry from an obfuscation
contest. Usually, there are some hints there.

BTW, I did a copy'n'paste into BC++ 5.02, and it
doesn't compile.


GNU indent didn't like it neither.

I think it just isn't valid C code...


[1] c:\c\junk>cc obfusc.c
obfusc.c:3: warning: return type defaults to `int'
obfusc.c:3: warning: second argument of `main' should be `char **'
obfusc.c:3: warning: third argument of `main' should probably be
`char **'
obfusc.c: In function `main':
obfusc.c:6: warning: passing arg 3 of `main' discards qualifiers
from pointer target type
obfusc.c:7:3: warning: multi-line string literals are deprecated
obfusc.c:7:3: warning: unknown escape sequence: '\040'
obfusc.c:7: warning: passing arg 3 of `main' discards qualifiers
from pointer target type
obfusc.c:14: warning: passing arg 3 of `main' discards qualifiers
from pointer target type
obfusc.c:14: warning: passing arg 3 of `main' discards qualifiers
from pointer target type

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 14 '05 #7
Yes its from some contest and a winner I suppose.
I compiled it into .exe using MS VC++ 6.0.
What is obscure string.
Can someone tell in more detail. Its interesting. We can all get benefit of.
thanks cric.

"Steven" <so************ ******@yahoo.co m> wrote in message news:<11******* **************@ o13g2000cwo.goo glegroups.com>. ..
free2cric wrote:
Hi,
FOllowing is a program which is written by someone else.
Its output is a wonderful poem. I dont understand how it works

really.
can anyone tell.
thanks
cric


Yes, I remeber this program. It is valid and it compiles fine with
GCC, even though it generates plenty of warnings. I *think* it works
by having a obscure string, do some operations on it to make it into
the lyrics, name it a obscure name, delete all the white space, print
the different substring of the string, and use recursion to print the
whole thing.

This program uses recursion to print one of the most famous Christmas
songs, "Twelve Days of Christmas".

The output of the program is:

"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
sevean 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 eig hth day of Christmas my true love gave to me
eight maids a-milking, sevean 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, sevean 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, sevean 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, sevean 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, sevean 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."

You have to admit, whoever wrote the program was pretty good.

Nov 14 '05 #8
"free2cric" <fr*******@yaho o.com> wrote in message
news:e8******** *************** ***@posting.goo gle.com...
Yes its from some contest and a winner I suppose.
I compiled it into .exe using MS VC++ 6.0.
My VC++6.0(SP6) rejected it (but perhaps it got
distorted by my newsreader).
What is obscure string.
It's in the code. Actually there are two strings
(not counting the two 'printf()' format strings):

"@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'}{nlw b!/*de}'c \
;;{nl'-{}rw]'/+,}##'*}#nc,',# nw]'/+kd'+e}+;\
#'rdq#w! nr'/ ') }+}{rl#'{n' ')# }'+}##(!!/"

and

"!ek;dc \
i@bK'(q)-[w]*%n+r3#l,{}:\nu wloca-O;m .vpbks,fxntdCeg hiry"
Can someone tell in more detail.
Tell what.
Its interesting.
Perhaps it is to some. I suggest that if you want to
figure out how it works, do one or both of:

1. Work through it with pencil and paper.

2. Watch it with a debugger. (this might involve obtaining
an implementation that doesn't reject the language
violations.)
We can all get benefit of.


Some might, others not. It could also cause some
to believe it's valid code.

BTW please don't top-post in comp.lang.c. Thank you.

-Mike
Nov 14 '05 #9

"free2cric" <fr*******@yaho o.com> wrote in message
news:e8******** *************** ***@posting.goo gle.com...
Yes its from some contest and a winner I suppose.
I compiled it into .exe using MS VC++ 6.0.
What is obscure string.
Can someone tell in more detail. Its interesting. We can all get benefit of. thanks cric.


I just tried VC++ 6.0 and no got even more errors than with BC++ 5.02.
In any case, if you look at the code, it's recursively calling main()
depending
on "t", end at the end, it does a putchar(). It shouldn't take more than a
few
hours with a debugger to figure out "exactly" how it works, but I kinda
doubt that anyone will do it for you. ;-)
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
8504
by: anuradha.k.r | last post by:
hi, i am writing a socket program in python,both client side and server side.I've written the client side which is working perfectly fine(checked it against server program written in C).but as for my server program written in python it simply hangs.it does not show any error also.I've tried sample programs available .I don understand what the reason is as i am quite new to it. here is teh server side program: ///////////////////////
6
8788
by: William J. Leary Jr. | last post by:
I'm running a VB6 program, the IDE for a compiler. Paste doesn't work if the text was cut/copied from within the program. That is: 1. Cut/copy inside the program, can't paste. Program: CTRL-V doesn't work, "Paste" grayed out in menu. 2. Cut/copy inside the program, CAN paste to another program (i.e.: Notepad).
7
2237
by: jan.dostrasil | last post by:
Hello, I'm new to c - so sorry if this is off topic here, please advice at least where should i ask... ;) I have a program in c which is working fine, it reads everything from pipe, modifies output data a bit and writes to stdout. When it is executed without parameters, program works fine. But what if I'd like to pass some extra configuration parameters to my program? 1. c:\> pipetest < file_in > file_out // this works
23
2366
by: JoeC | last post by:
I am a self taught programmer and I have figured out most syntax but desigining my programs is a challenge. I realize that there are many ways to design a program but what are some good rules to follow for creating a program? I am writing a map game program. I created several objects: board object that is an array of integers each number 0-5 is a kind of terrain, a terrain object that is an array of terrain types and each number of...
5
2624
by: Igor | last post by:
Hi! We built VB6 application to work with Reporting Services server. To connect to reporting server has been created a special assembly with .NET VS2003. While we execute our program on local machine, every thing works. But when we put the whole program on network drive, the VB6 program could not create required object from .NET assembly. Nothing we done were not useful to help to solve the problem. Does anybody have idea?
27
2164
by: Neil | last post by:
Hello all! I wrote program with a array of pointers, and I suspect they are pointing at each other in the Do ...While loop. Something is messed up with the increment variable word. A program clip of what I'm talking about. #include <stdio.h> #include <string.h>
9
4420
by: Tyler | last post by:
Hello All: I am currently working on a project to create an FEM model for school. I was thinking about using wxPython to gather the 12 input variables from the user, then, after pressing the "Run" button, the GUI would close, and the 12 input variables would then be available for the rest of the program. So far, what I have been able to do is mostly a reverse engineering job to get the frame to look right and return the text variable...
2
6864
by: test3 | last post by:
Hello folks, I'm using System.Diagnostics.Process to start a thirdparty program (that works perfectly when started via command line). I'm using Process.StandardOutput to get the output of the program. That works for 95 %, but the other 5 % it doesn't. It seems to me that the started process just hangs, and therefor my program hangs, too (p.WaitForExit()). I researched that this only happens when the output of the program is longer than...
0
1694
by: bvdb | last post by:
Hi Everyone, One of my customers lives in Taiwan and can only make my program work if he changes his Regional and Language Options to English from the Simplifies Chinese that his computer is normally set to use. Switching back and forth is very inconvenient for him. Is there a way that I can compile my program so that it works with the Regional Options set to Simplified Chinese? I set my PC Regional Options to Simplified Chinese,...
0
8083
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8547
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8224
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8406
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7013
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6062
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5517
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2535
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1393
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.