Obfuscated C Code Contest 2006. Please explain sykes2.c
stackoverflow.com
stackoverflow.com
[1] http://reprog.wordpress.com/2010/03/21/the-hacker-the-archit...
Stackoverflow has serious problems.
[1] http://stackoverflow.com/questions/15429479/obfuscated-c-cod...
main(O){10<putchar(4^--?77-(15&5128>>4*O):10)&&main(2+O);}
I enjoyed the extra mini-confusement from using a capital O as a variable name. :)I believe there is a mistake in this snippet of code: `--` triggers a syntax error. Shouldn't it be
main(O){10<putchar(4^--O?77-(15&5128>>4*O):10)&&main(2+O);}
My obfuscated C experience being quite limited, could you tell me how you determined all those magic values in order to print the right string?Thank you
I had to double-check that it's right in my profile on Stack overflow (which is where I copied it from for the above comment), but it is. That's even stranger.
Essentially, it's a loop that unpacks my name and prints it, letter by letter, from the constant 5128. Four bits is being used per letter, and I tried to compress the number by subtracting an offset from the ASCII codes of each letter (that's the 77).
It's been ~14 years or something since I first wrote this, and I'm pretty sure I was inspired by an Obfuscated C contest entry then, too. :)
> stordoff@stordoffs-MacBook-Pro:~ $ gcc HN.c && ./a.out
> EMIL
main(O){10<putchar(5^--O?82-(31&4763657>>5*O):10)&&main(2+O);}"Obfuscated C and Other Mysteries" by Don Libes
"C Companion" by Allen Holub
Don Libes' book actually uses Obfuscated C code entries as interesting instructional examples and Holub's book is a nice intermediate book between K&R and "Expert C Programming".
I never see Holub mentioned much by other C programmers but I think his books are awesome. He actually also has a really good compiler book called "Compiler Design in C" that showed how to build a C compiler from the ground up - with a lot of practical details I never really see in other books in that area. He even had a cool curses implementation to go along with it where you could watch the parsing occur visually, and wrote a curses-like library in assembly so you could run it all on DOS too. He used to write the C Chest columns for Dr Dobbs back in the day and the book "C Chest and Other C Treasures" contains a collection of those articles and other code that C programmers would find interesting. But that book is harder to find these days.