obfuscated C

12 days of christmas

Posted 29 May 2009 - 01:24 PM

I snagged this Obfuscated C code which prints out the 12 Days Of Christmas song, however, WTF?! I don't see how any of this can print out the actual verses and everything correctly it's just a bunch of symbols. Crazy. Anyone wanna help in breaking this down and figuring out it means?

I know the point of the Obfuscated C is to keep people from reading your code, however, this is ridic-uh-lous.

Re: 12 days of christmas

Re: 12 days of christmas

Posted 29 May 2009 - 01:31 PM

Haha, yeah, I have been on and off looking at this through the past week and a half, and still, I got nothing. It is quite obfuscated... well i'd be pretty pissed off if I were on a project with someone and for their portion they handed this to me, impressed, but pissed. I guess it could cause job security as they're the only person who knows how it works. LoL.

Re: 12 days of christmas

Posted 29 May 2009 - 02:14 PM

Well I believe that this code requires an older compiler. Usually if I can get them to compile that I have made some headway into deciphering them. Many of the IOCCC entries just don't compile on modern compilers.

Re: 12 days of christmas

Re: 12 days of christmas

Posted 29 May 2009 - 06:30 PM

Not bad at all, I just don't understand it cause it compiles fine with no other header files or anything else required, just a simple copy, paste, compile and run. I don't get it, it's absolutely ludicrous.

Re: 12 days of christmas

Posted 29 May 2009 - 07:07 PM

My code is really just simple substitution.

I started by trying to make my code as small as possible by substituting meaningful variable names with single letters. Then I replaced if's with ?: and creatively used the comma operator. I used a couple of macros to shorten some of the common symbols.

There are many other things that you can do. The code that you presented earlier uses recursion to mask what it is doing. Plus in previous versions of the C standard things were a little more lax (like not having to give a return type) and that code obviously makes use of some of these features.

Some obfuscated code includes misleading information such as functions that don't really do anything, or functions that are defined inside of comments or macros.

Preprocessor metaprogramming often comes into play. especially since you can define and undefine and redefine the same symbol so just when the follower thinks they understand what something does it changes.

One of the big tools is to use misdirection -- make the user think they are looking at a string when in fact the quotation marks are part of two macros and so only seem to be delimiting a string.

Sometimes the magic is actually in the make file which defines 1 macro which expands to flash out the real code -- since the macro is not in the code it form a sort of "key" to compiling the program.

Re: 12 days of christmas

Posted 30 May 2009 - 10:34 AM

well I believe the first clue is the Unix format for main():int main(int , char **, char **); - I have intentionally remove the names because in this program those will be meaningless (except for the first use of main).

Also note that the string in the middle is NOT (as I initially thought) some kind of preprocessor magic. The string is encoded (at least from what I got from Wikipedia).