Saturday, May 3, 2014

Code Obfuscation



Code obfuscation is the art of writing your code so that other human beings would tear their eyes out halfway through reading the code. At lower levels, some techniques include confusing identifiers, reversed array indexing, or look-alike characters.  For example,

“area = length * width” would become “a = aa * aaa”,
“2[arr]” instead of “arr[2]”, and
“10l0l” which I’m sure you read as 10101.

When writing obfuscated code, one should seek to violate all the good coding practices. Although this goes against the principle of writing elegant and well-documented code, it does serve a huge purpose.  

Reverse engineering is a big topic when it comes to software, especially in terms of security, and it involves the process of going backwards through the software development cycle; one can choose to remove copy protection or personally customize reversed engineered software. Programmers can obfuscate their code on purpose to deter reverse engineering and re-engineering. Even if a malicious user manages to obtain the source code, reverse engineering the obfuscation will prove to be a daunting task.

Certain programming languages like C, C++, and Perl have characteristics that make them easier to obfuscate. There are even contests for whoever could write the best obfuscated code, or worst, depending on who is reading the code. Some examples are the Obfuscated Ruby Code Contest (IORCC) and the International Obfuscated C Code Contest (IOCCC).  One of my favorites is the winner of the 1988 IOCCC for best layout by Brian Westley:

#define _ -F<00||--F-OO--;
int F=00,OO=00;main(){F_OO();printf("%1.3f\n",4.*-F/OO/OO);}F_OO()
{
            _-_-_-_
       _-_-_-_-_-_-_-_-_
    _-_-_-_-_-_-_-_-_-_-_-_
  _-_-_-_-_-_-_-_-_-_-_-_-_-_
 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
 _-_-_-_-_-_-_-_-_-_-_-_-_-_-_
  _-_-_-_-_-_-_-_-_-_-_-_-_-_
    _-_-_-_-_-_-_-_-_-_-_-_
        _-_-_-_-_-_-_-_
            _-_-_-_
}

The code above calculates the value of pi by looking at its own area.
             


Sources:  
"Obfuscated Code." Princeton University. N.p., n.d. Web. 04 May 2014.
"Winning Entries." Previous IOCCC Winners with Spoilers. N.p., n.d. Web. 04 May 2014.

3 comments:

  1. I like the topic, I like the example used. More examples would have been helpful like a time where writing code like this actually helped deter someone from stealing code. Also, do you do this in your coding? What kind of techniques are there for making your code look like jiberish to everyone else? Is it feasible in a tech company where other people have to read your code in order to build on it.

    ReplyDelete
  2. Thanks Andy. I don't obfuscate my code often since I need to submit most of them for my professors to view; I do abuse the ternary operator whenever I see fit, but even that is not really considered obfuscation. I am not familiar with advanced obfuscation techniques, although I am sure there are many. If you want to obfuscate your code, follow the rules that I've listed, and also remember to break as many of the rules you've learned so far as you can. In a developing environment, I would not imagine developers from a team obfuscating their code and giving it to their team to look at and build on as that would result in many deaths. However, if a product is finished, I am sure most companies use obfuscators on their product before releasing to the public. One reason is because copyright software are not enough to stop hackers from reverse engineering the product to produce a free version for themselves; obfuscated code will help prevent tampering of the product.

    ReplyDelete
  3. #TWB provides #Technical #Communication #Services and publishing services provider. #TWB course in #Technical #Communication, you can become a #Technical #Writer, a #Business #Communicator, technical writing and communication or an Instructional Designer. Each of these fields offers tremendous potential based on your writing abilities, and technology awareness.
    TWB Technical Communication Services | Publishing Services Provider




    ReplyDelete

UA-49607316-1