Skip to main content

A lightweight, open-source tool for Python code obfuscation. CodeEnigma helps protect your logic from reverse engineering and unauthorized access, making it a practical alternative to PyArmor for securely distributing your Python applications

Project description

Image

License: MIT Python Version PyPI Ruff Downloads

A lightweight, open-source tool for Python code obfuscation. CodeEnigma helps protect your logic from reverse engineering and unauthorized access, making it secure to distribute your Python applications.

🔒 Why CodeEnigma?

After searching extensively for a free and open-source Python obfuscation tool, I realized that most available options were either paid, closed-source, or opaque in how they worked. I wasn't comfortable letting a black-box tool encrypt my production code without knowing exactly what it was doing — especially when it had access to sensitive logic.

So I built CodeEnigma — a transparent, self-contained solution that gives you full control over the obfuscation process, with no hidden logic and no external servers involved.

This project is inspired by PyArmor but with a different approach.

High Level Architecture

Image

The working principle of CodeEnigma is simple:

  1. The user provides the path to the Python module to obfuscate.
  2. CodeEnigma reads the module's source code.
  3. An AES-256 key is generated using a secure random number generator and set in private.py
  4. Obfuscation runs file by file running the following steps:
    • 4.1. Compile using compile(code, str(file_path), "exec")
    • 4.2. Compress the byte code using zlib.compress(compiled_code)
    • 4.3. Encode the compressed byte code using base64.b64encode(compressed_code)
    • 4.4. Encrypt the encoded byte code using AESGCM(SECRET_KEY).encrypt(NONCE, obfuscated, associated_data=None) refer for more details:
  5. CodeEnigma creates a new module with the obfuscated code.
  6. A codeenigma_runtime.pyx file is created with the deobfuscation logic to decrypt and execute the obfuscated code.
  7. The runtime is compiled to a Python extension module using Cython. Also generates a codeenigma_runtime.whl file for distribution.
  8. End of process, the obfuscated module is ready to be distributed as wheel files.

Features

  • 🔒 Strong encryption using AES-256
  • 🔄 Simple API for obfuscating any python module
  • 🔑 Secure and dynamic key generation
  • 🛠️ Command-line interface for easy integration into build processes
  • 📦 Lightweight and dependency-minimal

Installation

Using Poetry:

poetry add codeenigma

Using pip:

pip install codeenigma

Usage

CodeEnigma comes with a user-friendly command-line interface powered by Typer. The CLI provides helpful prompts and rich output.

Basic Usage

To obfuscate a Python module:

codeenigma obfuscate /path/to/your/module

Command Line Options

  • --expiration, -e: Set an expiration date for the obfuscated code (YYYY-MM-DD)
  • --output, -o, --dist: Specify output directory (default: 'dist')
  • --verbose, -v: Show detailed output

Examples

Obfuscate with an expiration date:

The following example will obfuscate the module and set the expiration date to December 31, 2025, at 23:59:59+0530 (IST).

codeenigma obfuscate /path/to/your/module -e "2025-12-31 23:59:59+0530"

Specify custom output directory:

codeenigma obfuscate /path/to/your/module -o custom_output

Version Information

To check the installed version:

codeenigma version

Contributing

Contributions are welcome! This is a complete free and open-source project. If you have any suggestions or find any bugs, please open an issue.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Built with ❤️ using Python
  • Uses cryptography for secure encryption
  • Uses Cython for compiling the runtime
  • Logo Credits, Claude 🫡

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codeenigma-1.0.4.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codeenigma-1.0.4-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file codeenigma-1.0.4.tar.gz.

File metadata

  • Download URL: codeenigma-1.0.4.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.10.7 Darwin/24.5.0

File hashes

Hashes for codeenigma-1.0.4.tar.gz
Algorithm Hash digest
SHA256 7feedd37672e9fa22307a390368f32589ca953ffd8ddf88f5bf43d70dfb12507
MD5 275140591f735ad16b920b693cd8cf60
BLAKE2b-256 6107a77b38ff4560772e8c9e1fc1c86228900f35dfffe97c2d099222a6d384d4

See more details on using hashes here.

File details

Details for the file codeenigma-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: codeenigma-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.10.7 Darwin/24.5.0

File hashes

Hashes for codeenigma-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8e7d5a47ac26270381ecd4500e7825a6ccec4f63c9259cae1ab250fd82d8a4ad
MD5 a998dc78f5fe18617525ca0639363303
BLAKE2b-256 d9d16dca197bb9ba61c0651e3d4b62688fed9e589bc03ec899b67c1ed6c395fd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page