By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,496 Members | 2,325 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,496 IT Pros & Developers. It's quick & easy.

obfuscated code

P: n/a
I just came across following obfuscated code which prints map of a
asian country India......
Can any body help me in understanding what is happening in this
program.......
***********************************
#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);
return 0;
}
Nov 15 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 15 Nov, 05:04, "c.lang.mys...@gmail.com" <c.lang.mys...@gmail.com>
wrote:
I just came across following obfuscated code which prints map of a
asian country India......
Can any body help me in understanding what is happening in this
program.......
***********************************
#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);
return 0;

}
Exactly which piece of code don't
you understand? Is there something
syntactic that you don't get? At
first, I thought you'd made a typo
when I saw the 'XDt!" [b+++1]', but
it's just an instance of:

2[g]

where g is an array. Which part confuses
you?

(Note that this program is ... not reliable.)
Nov 15 '08 #2

P: n/a
"c.***********@gmail.com" <c.***********@gmail.comwrites:
I just came across following obfuscated code which prints map of a
asian country India......
Can any body help me in understanding what is happening in this
program.......
***********************************
#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);
return 0;
}
I think I've got it.

(spoiler space, scroll way down)




Further...





Further...






Further...









Still further...







Further...




Further...







Just a little further...








Nearly there...






Okay, here we are.

First, let's clean it up by replacing some of the character constants
with integers, and simplify the argument of putchar(). Note that `33^b&1'
simplifies as `(b & 1) ? 32 : 33', which in ASCII translates to

(b & 1) ? ' ' : '!'

Also, note the inner `for' loop just repeats a-64 times.

int main(void) {
int a,b,c;
const char str[] = "- FIGURE ...";
int a;
int b=10, c=10;
while ((a = str[b + 21]) != '\0') {
int i;
for (i = 0; i < a - 64; i++) {
c++;
if (c == 90) {
c = 10;
putchar('\n'); /* '\n' == 10 */
} else {
if (b & 1)
putchar(' ');
else
putchar('!');
}
}
b++;
}
return 0;
}

So `a' is set in sequence to the integer values of the characters from
`arr', starting with number 31. The first 31 characters
"- FIGURE?, UMKC,XYZHello Folks," have no effect; we could just as
easily omit them and change the indexing appropriately. On each
iteration b is incremented.

The inner loop prints a-64 characters. Depending on whether b is even
or odd (which doesn't change during the inner loop), most of the
characters are either ' ' or '!'. The variable c ensures that every
80th character output is '\n', so we get 80 column lines.

The upshot is that we print alternating runs of spaces and of '!', where
the characters in the string specify how long the runs are. The lines
are wrapped at 80 columns to produce a 2-D image.

So the string is just a (strangely) RLE encoded image, and the purpose
of the code is to decode and display the image.

(If by some bizarre eventuality this is homework, I ask that you credit
me in your submitted assignment. I also ask that you tell your
instructor from me that he or she has a perverse mind.)
Nov 15 '08 #3

P: n/a
On 15 Nov, 07:26, Nate Eldredge <n...@vulcan.lanwrote:
"c.lang.mys...@gmail.com" <c.lang.mys...@gmail.comwrites:
I just came across following obfuscated code which prints map of a
asian country India......
#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);
return 0;
}
So the string is just a (strangely) RLE encoded image, and the purpose
of the code is to decode and display the image.
But the encoding is wrong!! Change the last line to
"Hq!Wfs XDq!" (ie, s/t/q)

Nov 15 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.