Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Obfuscated C Code Contest 2006. Please explain sykes2.c (stackoverflow.com)
227 points by gedrap on April 10, 2013 | hide | past | favorite | 23 comments


I was at university with Steve, the author of this program. A couple of years ago, when I wrote "The hacker, the architect and the superhero: three completely different ways to be an excellent programmer" [1] he was the one I wrote about as The Hacker. So it seems more than appropriate that his work is now on Hacker News.

[1] http://reprog.wordpress.com/2010/03/21/the-hacker-the-archit...


It used to have an evil twin, the Underhanded C Contest [1] where the aim was to make an innocent program also do something evil in such a way that that it can be plausibly denied as accidental when the 'bug' is detected in a code review.

[1] http://underhanded.xcott.com/


"Used to have"? The underhanded C contest is back!


I'd love to see the converse, where the goal is to write code that looks really malicious but is actually a useful and helpful program -- like an apparent rootkit that actually implements a full webserver.


Thanks a lot for mentioning this, it's awesome !


Thanks alot. Love those stuff.


This is a really good explanation of my program, recommended.


do you happen to have a blog about this stuff? I'd love to read it


I have an ancient blog on my ancient website, not much about ioccc though - but you can at least find links to my previous entries here http://stephensykes.com


What really irks me is that this question [1], asking word-for-word the same question for a different year entry, that was posted two days later was closed as "too localized" and has -10 points, while this one has +452.

Stackoverflow has serious problems.

[1] http://stackoverflow.com/questions/15429479/obfuscated-c-cod...


It happens more and more often that a Google search for some problem sends me to a potentially useful Stsckoverflow question that has been closed for a ridiculous reason. At least, sometimes there are already answers or comments there that turn out being useful.


Taking a cue from reddit, it would be cool if someone started casualstackoverflow, with less strict moderation. Bonus points if closed questions can be imported.


That reminded me a lot of my old signature from my days on Slashdot:

    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. :)


Hello Emil,

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


Whoa, thanks! This must be some kind of copy-paste error. One problem with obfuscated code is obviously that it's way harder to spot those than in regular code. :)

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.


I can't even compile it on my mac and my C is too rusty, would you be kind enough to explain? =)


It's perfectly possible to run this on e.g. Ideone (http://ideone.com).

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. :)


There's a typo in it, which is probably why it doesn't compile (other replies have the correct version). This is the output:

> stordoff@stordoffs-MacBook-Pro:~ $ gcc HN.c && ./a.out

> EMIL


Interesting, tried making my version

    main(O){10<putchar(5^--O?82-(31&4763657>>5*O):10)&&main(2+O);}


I used to avidly reverse engineer the IOCCC entries when announced. It was a wonderful learning experience that teaches you quite a bit about C that you don't get from a mainstream book. Time well spent.


I enjoyed 'Expert C Programming: Deep C Secrets' for the same reason. Anyone know if there are other more modern books along similar lines?


Neither are recent, but the following are both good:

"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.


Thanks! I was thinking it would be great to have a new revision of one of these books that included material from C99 and newer.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: