Obfuscating a Function – How not to write Code
Some time ago, I had to write a pretty simple function that converts an integer value into a new “format.” The function ended up being easy-to-read code. For reasons I do not remember, I decided to obfuscate the purpose of the function slightly, and I ended up with the following:
If you run the code for different values of x
in the function main(),
you will quickly discover the function’s purpose, whatDoIdo().
If you are more dedicated, you can decrypt the code and guess its functionality without running it once. Indeed, you should prevent writing code like this at work or university since your colleagues/classmates or others who have to read your code most likely won’t appreciate this kind of programming style.
If you do not have a compiler at hand, you can take a look at some sample outputs that should appear familiar.
Click here to see some examples
Any guess? If not, then take a look at some more outputs:
Click here to see more examples
There is even an annual contest for obfuscated C code on https://www.ioccc.org/. IIf you are interested in submitting an entry for the next contest, the degree of obfuscation should be significantly higher than in this trivial example. The winning entries of the past years are really worth looking at.
Enjoy Reading This Article?
Here are some more articles you might like to read next: