Search code examples
rubyobfuscationcopy-protection

Any easy way to hide a little bit a Ruby Code?


I sought for a solution to make a Ruby code much more unreadable.

In fact i'm not interested about obfuscating totally the code but getting a "one line *.rb file" or some thing like "Pretty Numbers" on this link should be appreciated.

Before posting here I passed hours to find a solution but can't get any script, gem or program to transform an easy readable code on something quite more hard to understand for "dummies".

Tried for example these ones but any can do the whole job easily.


Solution

    • Replace all variable, method or class names for 1-letter names, just like a, b or c.
    • Do you know DRY? Forget it. Repeat parts of the code to make it bigger and more complicated to understand. Try to also write the same piece of code in many ways.
    • Transform simple integers and string on big expressions or calculations.
    • Define extra functions and use undef after or define existing functions before the real definition.
    • Add things that does nothing between the code, or code that does something followed by another that undoes it.
    • Move parts of the code to the somewhere before and use heredoc to transform this code to a string. Then execute it where it should be in.
    • Merge everything in one line and forget indentation. After put new lines in the middle of instructions, try to draw a rectangle with the code or something like that.
    • Test the code. If it stopped working, I'm so sorry, you will never be able to read it again.

    Anyway, just make a mess in the code. But it have to be done manually.