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)

3
  • 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 Commented Mar 16, 2016 at 13:24
  • Related: stackoverflow.com/q/261638/1639625 Commented Mar 16, 2016 at 13:25
  • The problem of hidding compiled strings shown up for all langues. See stackoverflow.com/questions/1356896/… Commented Mar 16, 2016 at 13:30

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

4 Comments

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 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.
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, 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: stackoverflow.com/a/982310/1113207

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.