What is the logic behind this type of code?

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;

}

output-

India map
1 Like

Where did you get this?

srsly where did u get this code…this doesnt even compile successfully!!!

Here is the working


[1] . 

This is an obfuscated code to print the Map of India. 

The Code can mainly  be Divided in 4 parts :

**(i) The Mystery String :** 

Well it is type of [Run-length Encoding][2] where each character at even position tells us how many spaces to print and odd character tells us how many '!' to print. 

Also first 31 characters of this string are omitted. 

**For Eg:** 

The 32nd character is 'T' so the it will print space 'T'-64 times or (84-64)=20 times and the next character is 'F' so this tells to print 'F'-64 times the character '!' or (70-64) = 6 times.

**(ii) Outer Loop :** 

This loop traverse through the **Mystery String** and **b** is used as index of the character and **a** stores the value of the character . 


**(iii) Inner Loop :** 

The value of **c** goes from **10 to 90** **( ascii value of 'Z')** and it is used for printing the characters and the character are printed **a-64 times**.

**(iv) putchar :** 

The putchar can be re-written as :- 


    ++c;
    if(c=='Z') //Ascii value of 'Z' is 90
    {
       c/=9; // Here c becomes 10 which is the ascii value of newline
       putchar(c);
    }
    else
    {
       if(b&1)  //Here the trick used is ascii value of ! is 33 and of ' ' is 32 so he xors 33^(b&1)
          putchar('!');
       else
          putchar(' ');
    }



If you are interested in more such code read the about [International Obfuscated C Code Contest][3] . 


  [1]: http://ideone.com/oD9hRC
  [2]: http://en.wikipedia.org/wiki/Run_length_encoding
  [3]: http://en.wikipedia.org/wiki/International_Obfuscated_C_Code_Contest
9 Likes

@kunal361
Here is a working code http://ideone.com/oD9hRC

really awesome!!!

wow! something absolutely new :slight_smile:

1 Like

superb…thanks a lot!!!

1 Like

Well no problem, and you can find more obfuscated and awesome codes at www.ioccc.org

Sahi hai yar hame to pata hi Nahi tha Uske baare me thnx:)

//