Python Code Obfuscation And Encryption Techniques

Python requires a certain level of security awareness for commercial development, in order not to be easily reversed. Confusion and encryption are necessary. In order to increase the difficulty of code reading, source code confusion is very necessary, http://pyob.oxyry.com/ is an online Python code confusion website.  It should also be noted that this confusion is actually suspected by many people, because even if it is confused, it does not change the structure of the code.

1. Source Code Confusion.

So, if necessary, when programming, you can deliberately do things that make it harder to reverse:

  1. Structure changes slightly, merging several classes into the same file.
  2. Add innocuous paradigm-programming styles in object-oriented structures.

2. File Encryption.

  1. The most basic method is to publish pyc files, that is, to convert all .py source files into pyc for distribution .Using the above method can easily generate pyc, to preliminary hidden code. However, pyc can still be easily cracked.
  2. Another solution is to use cython. Cython is a superset of PYTHON that converts PYTHON files to c and compiles them into pyd files. Advantages: rich resources, suitable for rapid development. It’s faster when translated into C. The downside: there is no JIT support (resulting in pure python running slower than JAVA, JAVASCRIPT, and so on), so PyPy is available.
  3. A trick is to pull all the variables from somewhere in each module into a python file and use cython to process that file, which makes it more difficult for crackers to remove pyd file dependencies from other pyc files.

As an interpreted language, encryption is extremely difficult, open source code is the king, but in the case of should-encryption, you can choose the above encryption method or confusion method.