7 ms·
Obfuscated C Code Contest 2006. Please explain sykes2.c
- maurits 14y agoIt 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/ http://underhanded.xcott.com/
- Aurel1us 14y agoThanks alot. Love those stuff.
- JoachimSchipper 14y ago"Used to have"? The underhanded C contest is back!
- epsylon 14y agoThanks a lot for mentioning this, it's awesome !
- jplewicke 14y agoI'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.
- pointyhatuk 14y agoI 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.
- Serow225 14y agoI enjoyed 'Expert C Programming: Deep C Secrets' for the same reason. Anyone know if there are other more modern books along similar lines?
- mtoddh 14y agoNeither 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.
- Serow225 14y agoThanks! I was thinking it would be great to have a new revision of one of these books that included material from C99 and newer.
- unwind 14y agoThat 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. :)
- bru 14y agoHello 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
- unwind 14y agoWhoa, 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.
- joshguthrie 14y agoI can't even compile it on my mac and my C is too rusty, would you be kind enough to explain? =)
- unwind 14y agoIt's perfectly possible to run this on e.g. Ideone (http://ideone.com 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. :)
- stordoff 14y agoThere'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
- sdsykes 14y agoThis is a really good explanation of my program, recommended.
- MikeTaylor 14y agoI 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-architect-and-the-superhero-three-completely-different-ways-to-be-an-excellent-programmer/ http://reprog.wordpress.com/2010/03/21/the-hacker-the-archit...
- chrisdotcode 14y agoWhat 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-code-contest-2012-please-explain-endoh2-c?rq=1 http://stackoverflow.com/questions/15429479/obfuscated-c-cod...
- cefstat 14y agoIt 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.
- im3w1l 14y agoTaking a cue from reddit, it would be cool if someone started casualstackoverflow, with less strict moderation. Bonus points if closed questions can be imported.