Skip to main content

🔐 xor.py — Simple XOR Encryption Tool in Python

Author: 0xsweat
Date: 2025/05/24

xor.py is a lightweight XOR encryption and decryption tool written in Python 3. It features a command-line interface (CLI) for encrypting/decrypting text or files and supports key generation. Ideal for basic data obfuscation, CTF utilities, or educational use.


📦 Installation

Install via PyPI:

pip install xor-py

Or clone directly from GitHub:

git clone https://github.com/0xsweat/xor
cd xor
python3 xor.py --help

🚀 CLI Usage

🔑 Generate a Key

Create a random key (default: 4096 bytes) and it saves it to key.txt:

python3 xor.py -g

Customize key size and output file:

python3 xor.py -g -ks 2048 -o mykey.txt

🔒 Encrypt or 🔓 Decrypt a File

python3 xor.py -f input.txt -k key.txt -o output.enc

This applies XOR encryption/decryption using the provided key file. The process is symmetric — use the same command to encrypt or decrypt.


✍️ Encrypt/Decrypt Raw Input

If no input file is given, you'll be prompted to enter the plaintext and key manually:

python3 xor.py

Example prompt: (The asterik's are there for show, the actual program does not show anything during input.)

Text -> ********
Key -> ********
Output file -> result.txt

📚 Using as a Module

You can also import xor.py into other Python scripts:

from xor import xor, keygen

# Generate a 1024-byte key
key = keygen("key.txt", 1024) # outputting the key to a file is optional

# Encrypt a string
encrypted = xor("Hello, world!", "key.txt", key_from_file=True) # grabbing the key from the file

# Decrypt it back
decrypted = xor(encrypted.decode(), key) # using the key from memory
print(decrypted.decode())  # Output: Hello, world!

⚠️ Disclaimer

While xor.py uses a simple XOR cipher that is not secure for protecting sensitive or personal data, it has several practical and educational applications. XOR encryption is symmetric, lightweight, and easy to implement, making it useful for:

  • 🧠 Learning about basic encryption principles
  • 🛠️ Building custom obfuscation tools
  • 🧩 Capture The Flag (CTF) challenges
  • 🐞 Debugging or modifying encoded data
  • 🔁 Simple reversible transformations

However, it is not suitable for real-world secure communications or storing confidential information. For secure encryption, consider using industry-standard libraries such as cryptography or PyNaCl.


📄 License

MIT License

Metadata

Release files for xor-py 1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xor-py 1.1
File Size Uploaded
xor_py-1.1.tar.gz 3.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for xor-py 1.1
File Interpreter ABI Platform
xor_py-1.1-py3-none-any.whl Python 3 none any Details

Total release size: 7.1 kB

Release files / xor_py-1.1.tar.gz

Download URL xor_py-1.1.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
180dd63afc4bb42d30d34e6504b0167bd7d8d30885a29bc339163f0392479f21
BLAKE2b-256 checksum
How to use checksums
78545c5836c5916d55d15b2ab03f6f73398ddd11c9877721fe3d3a985fc3b123
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.11

Release files / xor_py-1.1-py3-none-any.whl

Download URL xor_py-1.1-py3-none-any.whl
Size 3.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b2bb8ba890d8dc979a3fc1f1c235a9a94a904ca81ed773bc6e8b0ba7687b0243
BLAKE2b-256 checksum
How to use checksums
3e4d82b94dfc0c0b2e00d3bfc497f1db9f6a365c4c3f199ebc800e0546aaa44f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.11

Release history Release notifications | RSS feed

This release

1.1 This release

2 release files

1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page