0

I would like to compile python script, so nobody will be able to easily read source (there is file inside and function to check some hashes - so I want to hide it). I tried py_compile.compile("script.py") but when I open compiled file (.pyc) in plaintext editor, I can see some strings and function names in readable form. I need to prevent this so it should not be easily readable.

What to use for this? (I am on linux, python 2.7)

peter
  • 4,289
  • 12
  • 44
  • 67
  • Obfuscating a script language is possible, but it is still doable to regenerate the original code, afaik. A better way is to use another language and compile everything in one file, imho – arc_lupus Mar 16 '16 at 13:24
  • Related: http://stackoverflow.com/q/261638/1639625 – tobias_k Mar 16 '16 at 13:25
  • The problem of hidding compiled strings shown up for all langues. See http://stackoverflow.com/questions/1356896/how-to-hide-a-string-in-binary-code – Rudziankoŭ Mar 16 '16 at 13:30

1 Answers1

0

You need python obfuscator. One more way is to compile your script to binary using Nuitka.

Community
  • 1
  • 1
Mikhail Gerasimov
  • 36,989
  • 16
  • 116
  • 159
  • thanks for comment. Please, how can I compile it with nuitka on linux? I mean, I just need to compile one script.py to one file (Recently I am on windows and I tried it but it created whole program distribution with dist files and dependencies, but I just need to compile this one script and not other dependencies, because I will run it on linux with whole python environment installed.) Maybe I am safe to compile it "nuitka script.py" on linux and just delete dist dir. Right? – peter Mar 16 '16 at 17:14
  • @peter I can't test it right now, but if i'm right, after "nuitka script.py" you'll get "script" binary file inside "dist" dir. By default no extra dependences would be included. – Mikhail Gerasimov Mar 16 '16 at 17:27
  • I tried now on linux. It produced one exe file (which I can run on linux, wow) But when I inspected this exe file in texteditor, I found my secret string which I want to "hide" (make unreadable). Maybe it is not possible to produce compiled binary code with hidden secret strings and my only way is just to use combination of hash functions to make it hard to find in my script source. – peter Mar 17 '16 at 07:57
  • @peter, if it's just string, neither compiller, nor obfuscator will hide it. Binary will "obfuscate" only your program logic. You can obfuscate string and place it (obfuscated string) in code with functions that will convert it to real string at run time. In binary form it would be hard to understand how you're de-obfuscating "visible" obfuscated string. Here's string obfuscatinon example: http://stackoverflow.com/a/982310/1113207 – Mikhail Gerasimov Mar 17 '16 at 08:44