Skip to content

0xsweat/xor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” 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

About

A simple script for using XOR to encrypt files, or data using python3, CLI or importable.

Topics

Resources

License

Stars

Watchers

Forks

Languages