Skip to content

Commit 17035b4

Browse files
Create README.md
1 parent 34c9a08 commit 17035b4

File tree

1 file changed

+345
-0
lines changed

1 file changed

+345
-0
lines changed

README.md

Lines changed: 345 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,345 @@
1+
# Python Binary Optimization Compiler Script Documentation
2+
3+
[![License](https://img.shields.io/badge/license-Custom-blue.svg)](LICENSE.md)
4+
[![Python Version](https://img.shields.io/badge/python-3.6%2B-blue)](https://www.python.org/downloads/)
5+
[![Cross-Platform](https://img.shields.io/badge/cross--platform-yes-brightgreen.svg)](#1-introduction)
6+
[![Performance Optimization](https://img.shields.io/badge/performance-optimization-brightgreen.svg)](#3-main-functions-of-the-script)
7+
[![Native Compilation](https://img.shields.io/badge/native-compilation-blue.svg)](#3-main-functions-of-the-script)
8+
[![Code Security](https://img.shields.io/badge/code-security-brightgreen.svg)](#7-recommendations-and-best-practices)
9+
[![Code Protection](https://img.shields.io/badge/code-protection-brightgreen.svg)](#1-introduction)
10+
[![Python Compiler](https://img.shields.io/badge/python-compiler-blue.svg)](#3-main-functions-of-the-script)
11+
[![Optimize Python Code](https://img.shields.io/badge/optimize-python--code-green.svg)](#3-main-functions-of-the-script)
12+
13+
*Version: 1.3*
14+
© 2024 αβ.net ([alphabetanet.com](https://alphabetanet.com)) - Alpha Beta Network. All Rights Reserved.
15+
16+
---
17+
18+
**Note:** This project is currently in **Beta Testing** and available for free.
19+
20+
**Table of Contents**
21+
22+
- [1. Introduction](#1-introduction)
23+
- [2. Installation](#2-installation)
24+
- [2.1 Installing Required Packages](#21-installing-required-packages)
25+
- [3. Main Functions of the Script](#3-main-functions-of-the-script)
26+
- [3.1 Compiling Python Scripts to Native Binaries](#31-compiling-python-scripts-to-native-binaries)
27+
- [3.2 Code Obfuscation and Protection](#32-code-obfuscation-and-protection)
28+
- [4. Detailed Description of Each Function](#4-detailed-description-of-each-function)
29+
- [4.1 Compiling to Native Binaries](#41-compiling-to-native-binaries)
30+
- [4.2 Applying Code Obfuscation and Protection](#42-applying-code-obfuscation-and-protection)
31+
- [5. Additional Features](#5-additional-features)
32+
- [5.1 Performance Optimization](#51-performance-optimization)
33+
- [5.2 Cross-Platform Compatibility](#52-cross-platform-compatibility)
34+
- [6. Usage Examples](#6-usage-examples)
35+
- [6.1 Basic Compilation of a Script](#61-basic-compilation-of-a-script)
36+
- [6.2 Specifying a Compiler](#62-specifying-a-compiler)
37+
- [7. Recommendations and Best Practices](#7-recommendations-and-best-practices)
38+
- [8. Alternative Solutions](#8-alternative-solutions)
39+
- [Appendix A: Installation of Required Packages](#appendix-a-installation-of-required-packages)
40+
- [Appendix B: Comparative Performance Benchmarks](#appendix-b-comparative-performance-benchmarks)
41+
- [Appendix C: Contact Information](#appendix-c-contact-information)
42+
43+
---
44+
45+
# 1. Introduction
46+
47+
The **Python Binary Optimization Compiler Script** is a powerful command-line tool designed to provide **performance optimization** and **code protection** for Python scripts. It compiles Python code into native machine code executables, offering significant speed improvements and enhanced security.
48+
49+
Key features of the script include:
50+
51+
- **Performance Optimization**: Achieves 60-100% performance improvement over standard Python execution, as measured by computational algorithms in the [Python Performance Benchmark Tool](https://github.com/alphabetanetcom/python-performance-benchmark-tool).
52+
53+
- **Native Compilation**: Converts Python scripts into native binaries, eliminating the need for the Python interpreter during execution.
54+
55+
- **Code Obfuscation and Protection**: Implements multi-layer protection techniques, including code obfuscation, encryption, and anti-debugging measures.
56+
57+
- **Cross-Platform Compatibility**: Supports Windows, macOS, Linux/Unix, and other operating systems with Python 3.6+ installed.
58+
59+
- **No Source Code Modification Required**: Works without requiring any changes to your existing Python scripts.
60+
61+
This tool is ideal for developers seeking to **optimize Python code**, protect their **intellectual property**, and adhere to **code security best practices**.
62+
63+
The Python Binary Optimization Compiler Script can also be effectively used alongside other solutions offered by the Alpha Beta Network cloud platform, including the [Python Obfuscator Online](https://obfuscator.αβ.net/), the [Secure Python Code Manager Script](https://github.com/alphabetanetcom/secure-python-code-manager), and the [Local Python Code Protector Script](https://github.com/alphabetanetcom/local-python-code-protector).
64+
65+
---
66+
67+
# 2. Installation
68+
69+
Before using the Python Binary Optimization Compiler Script, ensure that you have **Python 3.6+** installed on your system.
70+
71+
## 2.1 Installing Required Packages
72+
73+
The script requires the following Python packages:
74+
75+
- **requests**
76+
- **psutil**
77+
- **cryptography**
78+
- **setuptools**
79+
- **Cython**
80+
- **astor**
81+
82+
You can install them using pip:
83+
84+
```bash
85+
pip install requests psutil cryptography setuptools Cython astor
86+
```
87+
88+
Ensure that you are using the correct version of pip associated with your Python 3 installation. If you are using a virtual environment, activate it before installing the packages.
89+
90+
**Compiler Requirements**
91+
92+
Additionally, you need to have one of the following compilers installed:
93+
94+
- **mingw32** or **mingw64** (for Windows)
95+
- **gcc** (for Linux/Unix)
96+
- **msvc** (Microsoft Visual C++ Compiler for Windows)
97+
98+
---
99+
100+
# 3. Main Functions of the Script
101+
102+
The Python Binary Optimization Compiler Script provides the following main functionalities:
103+
104+
## 3.1 Compiling Python Scripts to Native Binaries
105+
106+
Compile Python scripts into native machine code executables, significantly improving performance by eliminating the overhead of bytecode interpretation.
107+
108+
## 3.2 Code Obfuscation and Protection
109+
110+
Apply multi-layer code protection techniques to the compiled binaries, including code obfuscation, encryption, and anti-tampering measures, enhancing code security and protecting intellectual property.
111+
112+
---
113+
114+
# 4. Detailed Description of Each Function
115+
116+
## 4.1 Compiling to Native Binaries
117+
118+
The script uses Cython to translate Python code into C code, which is then compiled into a native extension module (.pyd on Windows, .so on Unix-like systems).
119+
120+
**Command Syntax**
121+
122+
```bash
123+
python python_binary_optimization_compiler.py script_path [--compiler COMPILER]
124+
```
125+
126+
**Description of Parameters**
127+
128+
- `script_path` **(Required)**: Specifies the path to the Python script (.py) to compile.
129+
130+
- `--compiler COMPILER` *(Optional)*: Specifies the compiler to use. Options are `mingw32`, `mingw64`, or `msvc`. If not specified, the script attempts to detect an available compiler.
131+
132+
**Compilation Process**
133+
134+
1. **Preprocessing**: The script modifies the source code to prepare it for compilation, including handling `if __name__ == "__main__":` blocks.
135+
136+
2. **Cython Compilation**: Translates the Python code into C code using Cython, applying compiler directives and optimizations.
137+
138+
3. **Native Compilation**: Compiles the C code into a native binary using the specified compiler, leveraging platform-specific optimizations.
139+
140+
4. **Binary Module Creation**: Produces an optimized binary module that can be executed directly without the need for the Python interpreter.
141+
142+
## 4.2 Applying Code Obfuscation and Protection
143+
144+
After compiling the code, the script applies several layers of protection to the binary module to prevent reverse engineering:
145+
146+
1. **Variable and Function Name Obfuscation**: Renames variables and functions to obscure names, complicating code analysis.
147+
148+
2. **String Encryption**: Encrypts strings within the code to prevent easy extraction of sensitive information.
149+
150+
3. **Control Flow Obfuscation**: Alters the code's control flow to make it more complex and less predictable.
151+
152+
4. **Dynamic Key Validation**: Implements a key validation mechanism that requires a specific key to execute the code.
153+
154+
5. **Anti-Debugging Measures**: Incorporates checks to detect and prevent debugging or tampering attempts.
155+
156+
6. **Runtime Integrity Checks**: Validates code integrity at runtime to detect unauthorized modifications.
157+
158+
---
159+
160+
# 5. Additional Features
161+
162+
## 5.1 Performance Optimization
163+
164+
By compiling Python code into native binaries, the script achieves significant performance improvements, often in the range of 60-100% over standard Python execution. This is accomplished through:
165+
166+
- **Native Machine Code Execution**: Eliminates the overhead of the Python interpreter by executing code directly as machine instructions.
167+
168+
- **Platform-Specific Optimizations**: Utilizes compiler-specific flags and optimizations tailored to the target architecture.
169+
170+
- **Advanced Compilation Techniques**: Applies optimization techniques such as dead code elimination, function inlining, and loop unrolling.
171+
172+
## 5.2 Cross-Platform Compatibility
173+
174+
The script supports multiple operating systems and Python versions:
175+
176+
- **Operating Systems**: Windows, macOS, Linux/Unix.
177+
178+
- **Python Versions**: Compatible with Python 3.6 and above.
179+
180+
- **Compiler Support**: Automatically detects available compilers or allows specification of the compiler.
181+
182+
---
183+
184+
# 6. Usage Examples
185+
186+
## 6.1 Basic Compilation of a Script
187+
188+
Compile a Python script without specifying a compiler (automatic detection).
189+
190+
**Command**
191+
192+
```bash
193+
python python_binary_optimization_compiler.py my_script.py
194+
```
195+
196+
**Output**
197+
198+
- The optimized and protected binary will be saved in the `Native_Protected` directory as a compiled `.pyc` file.
199+
200+
## 6.2 Specifying a Compiler
201+
202+
Specify the compiler to use for compilation.
203+
204+
**Command**
205+
206+
```bash
207+
python python_binary_optimization_compiler.py my_script.py --compiler mingw64
208+
```
209+
210+
**Notes**
211+
212+
- Options for `--compiler` are `mingw32`, `mingw64`, or `msvc`.
213+
214+
---
215+
216+
# 7. Recommendations and Best Practices
217+
218+
- **Use Appropriate Compiler**: Ensure that the specified compiler is installed and properly configured.
219+
220+
- **Optimize Your Code**: Applying optimization techniques in your Python code can further enhance performance when compiled.
221+
222+
- **Use Clean Source Code**: For successful compilation and computation optimization, use the original .py source code without prior obfuscation or encryption. Obfuscated or encrypted code will prevent the compiler from performing necessary optimizations.
223+
224+
- **Test Compiled Binaries**: Thoroughly test the compiled binaries to ensure they function as expected.
225+
226+
- **Combine with Other Protection Tools**: For maximum code security, consider combining this script with other Alpha Beta Network solutions like the [Python Obfuscator Online](https://obfuscator.αβ.net/) and the [Secure Python Code Manager Script](https://github.com/alphabetanetcom/secure-python-code-manager).
227+
228+
- **Stay Updated**: Keep your compiler and Python environment up to date to benefit from the latest optimizations and security features.
229+
230+
---
231+
232+
# 8. Alternative Solutions
233+
234+
The Alpha Beta Network offers other tools for code protection and optimization:
235+
236+
- **[Python Obfuscator Online](https://obfuscator.αβ.net/)**: An online tool for cloud-based Python code obfuscation and secure usage via the Alpha Beta Network cloud platform.
237+
238+
- **[Secure Python Code Manager Script](https://github.com/alphabetanetcom/secure-python-code-manager)**: A command-line tool for securely sharing and protecting Python code using the Alpha Beta Network cloud platform.
239+
240+
- **[Local Python Code Protector Script](https://github.com/alphabetanetcom/local-python-code-protector)**: A tool that provides advanced encryption and obfuscation techniques for Python code, allowing secure code distribution without requiring an internet connection.
241+
242+
These solutions offer additional features such as flexible licensing, multi-level source code protection, and seamless code updates.
243+
244+
---
245+
246+
# Appendix A: Installation of Required Packages
247+
248+
Ensure that the following packages are installed:
249+
250+
```bash
251+
pip install requests psutil cryptography setuptools Cython astor
252+
```
253+
254+
**Compiler Installation**
255+
256+
- **Windows**: Install [MinGW-w64](http://mingw-w64.org/doku.php/download) for `mingw32` or `mingw64`, or install Microsoft Visual C++ Build Tools for `msvc`.
257+
258+
- **Linux/Unix**: Ensure that `gcc` and related build tools are installed (e.g., via `sudo apt-get install build-essential` on Debian-based systems).
259+
260+
---
261+
262+
# Appendix B: Comparative Performance Benchmarks
263+
The following benchmarks were conducted using the [Python Performance Benchmark Tool](https://github.com/alphabetanetcom/python-performance-benchmark-tool), which was specifically compiled using the Python Binary Optimization Compiler Script to ensure accurate performance measurements.
264+
The benchmarks demonstrate the performance improvements achieved by using the Python Binary Optimization Compiler Script.
265+
266+
**Benchmark Results**
267+
268+
- **Standard Python Execution**:
269+
270+
- *Matrix Multiplication* (200x200): Median time: 0.601605 seconds
271+
- *Recursive Fibonacci* (n=35): Time taken: 1.215701 seconds
272+
- *Bubble Sort* (List size 5000): Time taken: 0.903095 seconds
273+
- *Prime Number Generation* (Limit 30000): Time taken: 1.788207 seconds
274+
- *Summary Evaluation* (Higher is better): 4.151314
275+
276+
- **Compiled with Python Binary Optimization Compiler Script**:
277+
278+
- *Matrix Multiplication* (200x200): Median time: 0.289568 seconds
279+
- *Recursive Fibonacci* (n=35): Time taken: 1.083918 seconds
280+
- *Bubble Sort* (List size 5000): Time taken: 0.666851 seconds
281+
- *Prime Number Generation* (Limit 30000): Time taken: 1.012288 seconds
282+
- *Summary Evaluation* (Higher is better): 6.863445
283+
284+
**Performance Improvement**
285+
286+
- Overall performance improvement is approximately 65% based on Summary Evaluation metrics (improvement from 4.151314 to 6.863445)
287+
288+
**Note**: Benchmarks were conducted on a system with the following specifications:
289+
290+
- **Operating System**: Windows 64-bit
291+
- **Processor**: Intel64 Family 6 Model 165 Stepping 5, GenuineIntel
292+
- **Python Version**: 3.11.9
293+
294+
Results may vary based on hardware and environment.
295+
296+
---
297+
298+
# Appendix C: Contact Information
299+
300+
If you experience issues or have questions not covered in this documentation, please contact the **Alpha Beta Network Research Team**.
301+
302+
- **Website**: [https://alphabetanet.com](https://alphabetanet.com) | [https://αβ.net](https://xn--mxac.net)
303+
304+
- **Official Telegram Channel**: [https://t.me/alphabetanetcom](https://t.me/alphabetanetcom)
305+
306+
Stay connected to receive updates, provide feedback, and get early access to extended functionality.
307+
308+
---
309+
310+
© 2024 αβ.net ([alphabetanet.com](https://alphabetanet.com)) - **Alpha Beta Network**. All Rights Reserved.
311+
312+
---
313+
314+
# Frequently Asked Questions (FAQ)
315+
316+
**Q1: What are the system requirements for using this script?**
317+
318+
**A1:** You need Python 3.6 or higher, the required Python packages (`requests`, `psutil`, `cryptography`, `setuptools`, `Cython`, `astor`), and a supported compiler (`mingw32`, `mingw64`, or `msvc`).
319+
320+
**Q2: Can I use this script to protect my Python code from reverse engineering?**
321+
322+
**A2:** Yes, the script applies multiple code protection techniques, including obfuscation and encryption, to make reverse engineering significantly more difficult.
323+
324+
**Q3: Does the compiled binary work on any system?**
325+
326+
**A3:** The compiled binary is platform-specific. You need to compile your script on the target platform or ensure compatibility between systems.
327+
328+
**Q4: Do I need to modify my code in any way to use the compiled version of the script?**
329+
330+
**A4:** No, you simply replace your original .py script file with the compiled file, specifying a different extension if needed (the filename can remain the same).
331+
The compiled binary is designed to be a drop-in replacement for your original Python script. You don't need to make any code modifications to use it.
332+
Just replace the original .py file with the compiled version and it will work as before.
333+
This maintains the simplicity of deployment while providing the benefits of compilation and protection.
334+
335+
---
336+
337+
By utilizing the **Python Binary Optimization Compiler Script**, developers can achieve significant performance gains and secure their Python scripts effectively, adhering to **code security best practices** and **protecting Python code** from unauthorized access.
338+
339+
This script represents a robust solution for those looking to **optimize Python code**, implement advanced **code obfuscation in Python**, and enhance the overall **security** of their applications.
340+
341+
---
342+
343+
© 2024 αβ.net ([alphabetanet.com](https://alphabetanet.com)) - **Alpha Beta Network**. All Rights Reserved.
344+
345+
---

0 commit comments

Comments
 (0)