Home > Net >  how can i make the script unreadable?
how can i make the script unreadable?

Time:01-11

I want my code to become unreadable. Let the person who wants to use it run it, but I don't want it to be able to open and read the code, how can I do that?

CodePudding user response:

What you are looking for is called code obfuscation.

It is not really possible in Python but as mentioned in this response you could compile your code to bytecode:

python -OO -m py_compile test.py

Example:

$ cat test.py
print("hello")
$ 
$ python3 -OO -m py_compile test.py
$ 
$ cat __pycache__/test.cpython-39.opt-2.pyc 
a
?��a�@s
       ed�dS)ZhelloN)�print�rr�test.py<module>� 
$ 
$ python3 __pycache__/test.cpython-39.opt-2.pyc 
hello
$ 

CodePudding user response:

You can't exactly make it unreadable

There is no way to make it so the user can't read your file, but we can get close.

1. Executables

You can use pyinstaller as mentioned in this post.

It is very easy to compile, and you can use the command shown below:

Make sure you install it!

pyinstaller [options] script [script …] | specfile
// or
pyinstaller 

2. Byte Code

As @Gab mentioned, you can compile to byte code.

This a great solution as you don't need any external downloads, but the problem is that you must run it with the matching version of python. (Pointed out by @tdelaney).

If you want to use this solution, follow @Gab's post. (It's pretty great)

3. Just don't do it.

There is really no reason for you to do this.

The only reason I can think of is if you are making this paid, and don't want people to make illegal copies. In that case, you can use this post (It's about gamedev, though some of the ideas are consistant)


Good luck with your script!

  •  Tags:  
  • Related