Encrypted Code Snippet Sample
File name: iter_n.py
import time
def iter_from_n(n):
list_n = []
for index,value in enumerate(range(n)):
list_n.append([index,value])
return list_n
if __name__=="__main__":
t1 = time.time()
iter_from_n(100000)
t2 = time.time()
print ("花费时间:{}".format(t2-t1))
0. Execute the py file directly
Command: python iter_n.py
1.pyc encryption
Command: python -m compileall [directory|file.py]
Command: python iter_n.cpython-37.pyc
Description: Cannot directly call the internal package module
2.pyd encryption
2.1 Cython encryption
pip install Cython==0.29.22
gcc related environment to compile related files
setup.py file
from distutils.core import setup
from Cython.Build import cythonize
setup(name='iter_n',
ext_modules=cythonize('iter_n.py'))
2.1.1 Compile command
python setup.py build_ext --inplace
2.1.2 Compile command
python setup.py [build|build_ext]
python setup.py install
2.2 easycython encryption
pip install easycython
2.2.1 Compile command
easycython iter_n.py
2.2.2 Compile command
easycython iter_n.pyx
2.3 Module usage
2.3.1 Generate pyd file
2.3.2 Module call
test.py
from iter_n import iter_from_n
print (iter_from_n(10))
3.py2exe
pip install py2exe
setup.py file
#coding=utf-8
from distutils.core import setup
import py2exe
options = {"py2exe":
{
"compressed": 1, #压缩
"optimize": 2,
"ascii": 1,
"bundle_files": 1 #所有文件打包成一个exe文件
}
}
setup (
options = options,
zipfile=None, #不生成library.zip文件
console=[{"script": "iter_n .py", 'icon_resources': [(1, 'icon.ico')] }]#源文件,程序图标
)
3.1 Compile command
python setup.py py2exe
4.pyinstaller
pip install pyinstaller
Common parameters:
–icon=icon path
-F packaged into an exe file
-w use window, no console
-c use console, no window
-D create a directory containing exe and other dependent files
pyinstaller -h to view parameters
pyinstaller -F -w -i icon.ico iter_n .py
5. love
pip install pyarmor
5.1pyarmor encryption
pyarmor obfuscate --recursive [目录|文件.py]
5.2 Set the date of use
5.2.1 Generation date license
pyarmor licenses --expired 2024-01-01 目录
5.2.2 Generation date license
pyarmor obfuscate --recursive --with-license licenses/r001/license.lic iter_n.py
5.3 Encrypted files
5.4 Module call
test.py
from iter_n import iter_from_n
print (iter_from_n(10))