Skip to main content

An easy way to use xor in python3

Project description

🔐 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

Or clone directly from GitHub:

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

🚀 CLI Usage

🔑 Generate a Key

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

python xor.py -g

Customize key size and output file:

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

🔒 Encrypt or 🔓 Decrypt a File

python 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:

python 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

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

xor_py-1.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

xor_py-1.0-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file xor_py-1.0.tar.gz.

File metadata

  • Download URL: xor_py-1.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for xor_py-1.0.tar.gz
Algorithm Hash digest
SHA256 30f008b4467f4dc122a4a62580d52e9191f2d8d68101d63bccb20d6bd82f7a34
MD5 516eea6fca48849833006bb0f97f13a8
BLAKE2b-256 d9653fefd037c65f333f09bccc1268756cfbf1793546d211e880ee5ad2544018

See more details on using hashes here.

File details

Details for the file xor_py-1.0-py3-none-any.whl.

File metadata

  • Download URL: xor_py-1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for xor_py-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f4cf37bd7cc63b64aff4404605ca6268c12da127ef9189296439e4da3481e3a1
MD5 219be1948634f9cf695ce782caf99585
BLAKE2b-256 b5456fffc599e654787ff9dd9171fe02c15c8f77b27bef4a405b2134d2d5a666

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