1

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.

durron597
  • 31,968
  • 17
  • 99
  • 158
cz3ch
  • 409
  • 2
  • 11
  • 1
    Why would you want to do this? – Arafangion Aug 11 '11 at 01:19
  • @Arafangion Because I distribute a Ruby Script through "Ocra" gem library and when it's running, my script is fully accessible in the temporary folder of windows. – cz3ch Aug 11 '11 at 02:35
  • So what if it's fully accessible? Why is that a problem? They can copy it anyway. – Arafangion Aug 11 '11 at 12:02
  • @Arafangion Well "Ruby Scambler" for Sketchup do it like a charm but seems that nothing exists for gems yet :-/ – cz3ch Aug 11 '11 at 14:51
  • Ok, so you can make it a little more difficult to understand, but I suppose what I'm trying to say is: "Are you sure you're solving a real problem?". Notice how I didn't ask "What are you trying to hide?", because I don't care. Your source code is not that interesting. It might be interesting, but even if it were, no amount of 'obfuscation' would prevent me from knowing what it does. – Arafangion Aug 11 '11 at 16:09

3 Answers3

3

Encapsulate code in a string

string = "1+2; sneaky('something'); 'will be hidden'"

Encapsulate string in an array

array = [string]

Pack the contents of the array into a binary sequence

 array.pack('u') #=> "?<'50``\n..."

Copy & paste binary sequence in your code and evaluate it.

eval("?<'50``\n...".unpack('u').first) #=> 'will be hidden'
Tom Maeckelberghe
  • 1,969
  • 3
  • 21
  • 24
1
  • 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.

Guilherme Bernal
  • 8,183
  • 25
  • 43
  • Ok that's what I knew... Was seeking something like "Ruby Scambler" for Sketchup in fact or anything free like that ;-) I think I'll simply replace "CR" by ";" to get a one only line file. – cz3ch Aug 11 '11 at 02:43
0

Misspell variable and method names. Don't wast characters.

Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338