I want to see you again.
As an interpreted language, Python is inherently more difficult to encrypt. But sometimes we have to consider the encryption of the code when we release a python product to avoid source code leaks. To this end, I have reviewed some of the information and studied several common ways of python code encryption. Record it here.
The pyc file is a binary file, but can be easily reversed, online decompile tool:
https://tool.lu/pyc/. Of course, there is also a solution to this problem. The solution is to modify the opcode in the python source code and then recompile the py code to prevent it from being reversed to some extent, because the reverser needs to know the modified opcode to be restored. If you use a proprietary Bytecode instruction set, then the usual Python disassemblers and decompilers won’t work on the pyc files produced by your private Python compiler, which is equivalent to protecting your Python code. But the price of doing this is that your Python application can only be run on your private Python interpreter. (actually not applicable when releasing a product)
The exe file is used for the Windows platform. It is usually packaged into exes using a packager (py2exe, PyInstaller, etc.). These tools are used to package a Python project into a single executable file for use (on a machine without a Python environment). However, all the pyc files or source files can be conveniently obtained through the compression package, which is essentially different from the executable file generated by C/C++ compilation. It is basically zero protection, so the exe needs to be packed.
Use cython to convert the core code py module file into a .c file, then compile it into a so(unix) file with gcc, or compile it into a pyd(windows) file.
1, server installation depends
2, write the setup.py file, the content is as follows:
3, run the following command