views:

1980

answers:

4

Do you know of any tool that could assist me in obfuscating python code?

+3  A: 

http://www.lysator.liu.se/~astrand/projects/pyobfuscate/

Or at http://freshmeat.net/projects/pyobfuscate/

Nick Fortescue
pyobfuscate is good... Google told me so!
Alterlife
+2  A: 

In many situations you can ship byte-compiled .pyc files instead of the .py source files. This gives you some level of obfuscation. As the pyobfuscate README suggests, this has limitations. But you may be able to combine the two approaches.

Greg Ball
+5  A: 

Your problem space is underspecified. Is this for a command-line app? Is this code supposed to be used as a library?

In addition to the two other answers, you could embed the code into a binary. When it starts, decode the code and eval the string. This works for a shared library extension as well. You could also do that with byte code, I think, but it wouldn't be as simple as calling Py_EvalCode.

py2exe or freeze are other solution, which convert the code into an executable. It just includes the code in the binary, and doesn't do any sort of serious obsfucation, but it's still harder than opening a .py file.

You could write the code in Cython, which is similar to Python and writes Python extension files in C, for use as a .so. That's perhaps the hardest of these to reverse engineer and still give you a high-level language for develoment.

They are all hackable, as are all solutions. How hard to you want it to be?

Andrew Dalke
+1 for Cython, which I have recently used and found it to be pretty good at what it does.
Dan
+1  A: 

Convert the code to Perl, then it will be utterly indecipherable :-)

mhagger