Obfuscation As A Learning Tool

 

So a few years ago I caught a glance of the IOCCC(The International Obfuscated C Code Contest) which inspired me to write this bit of C. All it does is output "HELLO WORLD" but it got me thinking; could obfuscation be used as a learning tool? Or even as a skill metric? I realized that even though I was attempting to solve a very simple task (outputing HELLO WORLD) I was going at it in a much different way. I wasn't thinking of the simplest, most practical or most maintainable solution. I was thinking of the most clever. Which we all know is bad:

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it."
- Brian Kernighan

But in this case the idea works in our favor. If we are as clever as possible writing the code it would take someone even more clever than ourselves to figure out what it does. Because in the end, although the code below looks quite complex and intimidating the only thing that needs to be done is breaking it down to its most basic forms. I'll leave that as an exercise to the reader since I could take a very long time explaining it piece by piece (I believe I wrote a paper on this bit of code, it ended up being around 10-15 pages long if I remember.)

This point may seem tangential at best to the idea that obfuscation could be used as a learning excercise but if you think about it there could be a very applicable place for it. A person may go along learning the syntax of a language or possibly even a couple best practices but may never actually learn how to program so their brain would never be able to correctly break a problem down into parts, which in the end, is what obfuscation does in an abstract manner. So perhaps wracking your brain against some obfuscated code can help you "think outside the box", or rather, inside the box by breaking a problem set into smaller pieces, something I admittedly forget to do much too often. So I'll leave you with the code to stew over (compiled with gcc) and the link to the IOCCC for some more things to wrap your head around.

Plain #include <stdio.h> inline void ___(int _$){printf( "%c",_$ );} int main( ){int _ , __; _ -=_;_++ ;__ -=__; __+=_+_;_++;_*=_*_;_*=_;_+=( _ /( __*__) ); _-=( __ *__)*__;___(_);_=(_--)-__; ___( _); __++;_+=__;__--;_+=__*__;___(_); __+=__%__; ___( _ );__++;_+=__;__--; ___( _ );_ /= __; _-= __*__;__++;_-= __; __--;___( _ );_*=__; _+=_/__;__++;_-=( __ * __ );__--;___( _ ); _-=((__*__) *__);___(_);__++;_+=__;___(_ ); _-=__;_-=__;__--;___( _ );_-=((__*__)*__ ); ___( _);_-= (__ * __ )*__;__++;_/=__;_/=__; __++;_ += __;___( _ );_-= __;return _-= _;}