Skip to main content

🔐 binencrypt

Recursive Python Code Encryption & Obfuscation

Version 2.7.5

Python 3.6+

License: MIT

binencrypt is a powerful tool that applies multiple recursive encryption layers to your Python source code. Each layer wraps the previous one with a unique sequence of encoding, compression, and serialization operations. The final output is a self‑executing Python script that unwraps all layers at runtime and runs your original code.

Designed for code obfuscation and intellectual property protection – not for cryptographic security. Use it to make reverse‑engineering harder, not impossible.


✨ Features

  • 🔁 Recursive Layering – Each layer encrypts the entire output of the previous layer (depth up to 10+).

  • 🧩 Dynamic Operations – Each layer picks a random sequence of 5–15 operations (e.g., base64, gzip, marshal, hex, etc.) based on a master key.

  • ⚡ Marshal Optimisation – Compiles your source to bytecode and serialises it with marshal, reducing final script size by 30‑50%.

  • 📦 Compact Output – Generates a single‑line Python script (or a readable multi‑line version) that is easy to distribute.

  • 🎯 Deterministic – Same key + depth yields the same encrypted output (useful for reproducible builds).

  • 📁 File Support – Encrypt any Python file; output is a standalone script.

  • ⚙️ Customisable – Control depth, operations per layer, and use of marshal.


📦 Installation

# Install from PyPI (soon)

pip install binencrypt



# Or install directly from source

git clone https://github.com/ishanoshada/binencrypt.git

cd binencrypt

pip install -e .

🚀 Quick Start

Encrypt a Python file with 10 recursive layers:

binencrypt -i my_script.py -o encrypted.py --depth 10

Run the encrypted script:

python encrypted.py

The output will execute the original my_script.py code after decrypting all 10 layers.


🛠 Command Line Options

| Argument | Description |

|----------|-------------|

| -i, --input | Input Python file (required) |

| -o, --output | Output file path (auto‑generated if not given) |

| --depth | Number of recursive encryption layers (default: 1) |

| --key | Master encryption key (auto‑generated if omitted) |

| --min-ops | Minimum operations per layer (default: 3) |

| --max-ops | Maximum operations per layer (default: 5) |

| --fast | Fast mode: min-ops=2, max-ops=4 |

| --marshal | Use marshal mode (compiles source to bytecode) – default |

| --no-marshal | Disable marshal mode (encrypts source as text) |

| --func | Alias for --marshal |

| --readable | Generate multi‑line readable output (not compact) |

| --compile | Compile the output to .pyc (using py_compile) |

| --decrypt | (Not yet fully implemented) |


📝 Examples

Basic encryption with default settings (3‑5 ops per layer, marshal on)

binencrypt -i app.py -o app.enc.py --depth 8

Use a specific key

binencrypt -i app.py -o app.enc.py --depth 10 --key "my-super-secret-2024"

Faster encryption (fewer operations per layer)

binencrypt -i app.py -o app.enc.py --depth 10 --fast

Generate human‑readable (non‑compact) output

binencrypt -i app.py -o app.enc.py --depth 5 --readable

Disable marshal mode (larger output, but easier to inspect)

binencrypt -i app.py -o app.enc.py --depth 5 --no-marshal

📊 Performance & File Size

| Depth | Mode | Size (approx) | Time (approx) |

|-------|------|---------------|---------------|

| 5 | marshal | 300 KB | 0.5 s |

| 5 | source | 500 KB | 0.7 s |

| 10 | marshal | 1.8 MB | 1.5 s |

| 10 | source | 4.5 MB | 4.0 s |

| 15 | marshal | 6 MB | 6 s |

Measured on a small 100‑line script. Actual results vary with code size and system.


⚠️ Security Disclaimer

binencrypt is an obfuscation tool, not a cryptographic security solution.

  • The encryption is reversible – anyone with the key and knowledge of the algorithm can recover the source.

  • It is designed to hinder casual reverse‑engineering, not to protect against determined attackers.

  • Do not use it to store passwords, API keys, or other sensitive data.

  • For real security, use established libraries like cryptography or Fernet.


📄 License

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


👨‍💻 Author

K.A. Ishan Oshada

GitHub · Email


🤝 Contributing

Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.


📚 More Information

  • How it works: Each layer uses a deterministic random sequence of operations derived from the master key and layer index. The innermost layer is either the original source code (or compiled bytecode). The outer layers encrypt that payload, producing a nested structure that unwraps at runtime.

  • Why use marshal? marshal.dumps() of a compiled code object is significantly smaller than the source code string, and it avoids the compile() overhead at runtime, making decryption faster.


Happy encrypting! 🚀

Download files

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

Source Distribution

binencrypt-2.7.5.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

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

binencrypt-2.7.5-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file binencrypt-2.7.5.tar.gz.

File metadata

  • Download URL: binencrypt-2.7.5.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for binencrypt-2.7.5.tar.gz
Algorithm Hash digest
SHA256 c13c35df868991e86c2727c57d53a0ce63142350d175262a476e9fab2067e75c
MD5 9b6f577483551e878ce1a8e404addb13
BLAKE2b-256 bdb690d3f0aa0f284c720086bbbf8ebf963ce31c539a42aa9dc4b6e6fb479c2d

See more details on using hashes here.

File details

Details for the file binencrypt-2.7.5-py3-none-any.whl.

File metadata

  • Download URL: binencrypt-2.7.5-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for binencrypt-2.7.5-py3-none-any.whl
Algorithm Hash digest
SHA256 6083b5335437b4d77817ba1c708824e004dca72cb12ece7a9a53f1193f5d7652
MD5 57dbf5a9f9375ccb3f376967bc07f69d
BLAKE2b-256 f5bdd31f6f20c7d33c9282b07959d3f9d453d79f43f8a3e4d19dda2b4f2fd54a

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 Sentry Error logging StatusPage Status page