This code prints the map of India. How does it work?
#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;
}
The long string is simply a binary sequence converted to ASCII. The first
forstatement makesbstart out at 10, and the[b+++21]after the string yields 31. Treating the string as an array, offset 31 is the start of the “real” data in the string (the second line in the code sample you provided). The rest of the code simply loops through the bit sequence, converting the 1’s and 0’s to !’s and whitespace and printing one character at a time.Less obfuscated version:
The
strangeclever part is in theputcharstatements. Take the firstputchar. ASCII'Z'is 90 in decimal, so 90 / 9 = 10 which is a newline character. In the second, decimal 33 is ASCII for'!'. Toggling the low-order bit of 33 gives you 32, which is ASCII for a space. This causes!to be printed ifbis odd, and a blank space to be printed ifbis even. The rest of the code is simply there to walk the “pointer”athrough the string.