LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-03-2003, 09:40 PM   #1
deadhead
LQ Newbie
 
Registered: Oct 2003
Distribution: Debian 'Woody"
Posts: 24

Rep: Reputation: 15
nice piece of code ....HOW DOES IT WORK?


hello,
your new newbie on the block here.
I came across this piece of code,fiddled around ,deleted some lines and could'nt figure out how it worked.any good coders to decode this one?
#include <stdio.h>
main()
{
int a,b,c;
int count = 1;
for (b=c=10;a="- FIGURE?, UMKC,XYZHello Folks,\
TFy!QJu ROo TNn(ROo)SLq SLq ULo+\
UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^\
NBELPeHBFHT}TnALVlBLOFAkHFOuFETp\
HCStHAUFAgcEAelclcn^r^r\\tZvYxXy\
T|S~Pn SPm SOn TNn ULo0ULo#ULo-W\
Hq!WFs XDt!" [b+++21]

for(; a-- > 64 ; )
putchar ( ++c=='Z' ? c = c/ 9:33^b&1);
getch();
}
thnks in advance and some more later!!!
 
Old 12-04-2003, 04:40 AM   #2
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
well this is an example of obfuscated coding.

what this piece of code is doing is :

in the first for loop
for (b=c=10;a="- FIGURE?, UMKC,XYZHello Folks,\
TFy!QJu ROo TNn(ROo)SLq SLq ULo+\
UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^\
NBELPeHBFHT}TnALVlBLOFAkHFOuFETp\
HCStHAUFAgcEAelclcn^r^r\\tZvYxXy\
T|S~Pn SPm SOn TNn ULo0ULo#ULo-W\
Hq!WFs XDt!" [b+++21]

first of all, it is assigning to 'a' a particular element in the string seen

suppose this were the line in code x=0;a="foobar"[x++ + 1];
a would assume the value = 'o'
...
in the second loop ...
a is being decremented till it is greater than 64 (ascii for 'A'),

inside putchar you see:
c being pre incremented ...and it is toggling between 32 (ascii ' ') and 33(ascii '!')

this is what is being repeated over and over to get the map of India.

hope i have been able to put some light ....
 
Old 12-05-2003, 12:00 PM   #3
vasudevadas
Member
 
Registered: Jul 2003
Location: Bedford, UK
Distribution: Slackware 11.0, LFS 6.1
Posts: 519

Rep: Reputation: 30
There is an annual competition for this sort of thing - the International Obfuscated C Code Contest.

http://www.ioccc.org/main.html
 
Old 12-05-2003, 10:39 PM   #4
deadhead
LQ Newbie
 
Registered: Oct 2003
Distribution: Debian 'Woody"
Posts: 24

Original Poster
Rep: Reputation: 15
thanks a lot.any good resources you recommend for the language in general and the above in particular?
 
Old 12-06-2003, 12:22 PM   #5
vasudevadas
Member
 
Registered: Jul 2003
Location: Bedford, UK
Distribution: Slackware 11.0, LFS 6.1
Posts: 519

Rep: Reputation: 30
For C programming, the main text is "The C Programming Language" by Brian Kernighan and Dennis Ritchie.
 
Old 12-06-2003, 04:41 PM   #6
h/w
Senior Member
 
Registered: Mar 2003
Location: New York, NY
Distribution: Debian Testing
Posts: 1,286

Rep: Reputation: 46
no documentation for obfuscated coding because you're not supposed to be coding that way.
 
Old 12-06-2003, 09:42 PM   #7
mymojo
Member
 
Registered: Oct 2003
Distribution: Slackware 9.1
Posts: 176

Rep: Reputation: 30
could someone recode this in a "proper" manner... that would be cool!
 
Old 12-07-2003, 12:52 AM   #8
deadhead
LQ Newbie
 
Registered: Oct 2003
Distribution: Debian 'Woody"
Posts: 24

Original Poster
Rep: Reputation: 15
thanx a lot guys,hope them obfu... coders die a horrible death in debugging hell!!!!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript Code doesnt work w/ firefox? swatward Programming 1 04-18-2005 06:54 PM
C++ question: can't figure out why this simple code does not work frankie_DJ Programming 2 12-25-2004 04:14 AM
echo does not work in php code suchi_s Programming 3 10-21-2004 03:39 AM
Why won't this Java code work? ludeKing Programming 9 05-28-2004 11:32 AM
nice does not seem to work in prioritizing large processes?? carlos123 Linux - Software 1 11-22-2003 04:33 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration