A lightweight command-line file encryption tool built with modern C++
Features • Installation • Usage • How It Works • Learning Journey
SafeBox is a command-line file encryption/decryption tool that uses the XOR cipher algorithm to secure your files. This project was built as part of my journey to master C++ programming, focusing on file I/O operations, binary data manipulation, and secure coding practices.
⚠️ Disclaimer: This tool is built for educational purposes. For production-grade security, consider using established encryption libraries like OpenSSL or libsodium.
| Feature | Description |
|---|---|
| 🔒 File Encryption | Encrypt any file type using XOR cipher with a custom key |
| 🔓 File Decryption | Decrypt encrypted files using the same key |
| 🗑️ Secure Shred | Optionally delete the original file after encryption |
| 📁 Binary Mode | Works with all file types (text, images, documents, etc.) |
| 💻 CLI Interface | Simple and intuitive command-line interface |
| 🎯 Cross-Platform | Works on Windows, Linux, and macOS |
- C++ Compiler (GCC, Clang, or MSVC)
- C++11 or later
# Clone the repository
git clone https://github.com/yourusername/SafeBox.git
cd SafeBox
# Compile using g++
g++ -o safebox main.cpp Encryptor.cpp -std=c++11
# Or using MSVC (Windows)
cl /EHsc main.cpp Encryptor.cpp /Fe:safebox.exe./safebox <mode> <filename> <key> [options]| Mode | Description |
|---|---|
-e |
Encrypt the file |
-d |
Decrypt the file |
| Option | Description |
|---|---|
--shred |
Delete the original file after encryption (with confirmation) |
# 🔐 Encrypt a file
./safebox -e secret.txt MySecretKey123
# 🔓 Decrypt a file
./safebox -d secret.txt.enc MySecretKey123
# 🗑️ Encrypt and shred original file
./safebox -e confidential.pdf SuperSecretKey --shred==========================================================
SAFEBOX FILE ENCRYPTOR
==========================================================
Usage: \.safebox <mode> <filename> <key> [options]
Modes:
-e : Encrypt the file
-d : Decrypt the file
Options:
--shred : Delete the original file after encryption
Example:
.\safebox -e myfile.txt K
Remember your key! Without it, decryption is not possible.
SafeBox uses the XOR (Exclusive OR) cipher, a symmetric encryption technique:
Encrypted = Original XOR Key
Original = Encrypted XOR Key
graph LR
A[📄 Input File] --> B[Read Byte]
B --> C[XOR with Key]
C --> D[Write to Output]
D --> E{More Bytes?}
E -->|Yes| B
E -->|No| F[🔐 Encrypted File]
- Binary File Handling: Uses
ios::binaryflag for raw byte operations - Cyclic Key Application: Key repeats cyclically for files larger than key length
- Memory Efficient: Processes file byte-by-byte, suitable for large files
- Error Handling: Comprehensive validation for file operations and user input
SafeBox/
├── 📄 main.cpp # Entry point and CLI handling
├── 📄 Encryptor.cpp # Core encryption/decryption logic
├── 📄 Encryptor.h # Encryptor class header
├── 📄 README.md # Project documentation
└── 🔒 test.txt.enc # Sample encrypted file
| Concept | Description |
|---|---|
| 📚 File I/O | Binary file reading/writing with ifstream and ofstream |
| 🔤 String Manipulation | Substring extraction, string finding operations |
| 🎛️ Command Line Args | Parsing argc and argv for CLI applications |
| 🏗️ OOP Principles | Class design with separate header and implementation files |
| Input validation and graceful error messages | |
| 🔢 Bitwise Operations | XOR operation for encryption |
| 📦 Modular Code | Separation of concerns with reusable components |
- ✅ Working with binary data in C++
- ✅ Building command-line applications
- ✅ Understanding symmetric encryption basics
- ✅ File system operations (read, write, delete)
- ✅ Memory-efficient stream processing
- ✅ Clean code organization and documentation
- 🔑 Stronger Encryption: Implement AES-256 encryption using OpenSSL
- 🔒 Password Hashing: Add key derivation function (PBKDF2/Argon2)
- 📊 Progress Bar: Show encryption progress for large files
- 📁 Directory Support: Encrypt entire directories recursively
- 🗜️ Compression: Add file compression before encryption
- 🔐 Key File Support: Use key files instead of command-line keys
- 🧪 Unit Tests: Add comprehensive test suite
- 📝 Logging: Add detailed logging for debugging
- 🖥️ GUI Version: Create a graphical user interface
- 🔄 Parallel Processing: Multi-threaded encryption for faster processing
Important: XOR cipher alone is NOT cryptographically secure for protecting sensitive data.
- Key Vulnerability: Key can be recovered through known-plaintext attacks
- No Authentication: Doesn't verify file integrity
- Key Repetition: Short keys create patterns in encrypted data
- Use established libraries (OpenSSL, libsodium)
- Implement proper key derivation functions
- Add message authentication codes (MAC)
- Never hardcode keys in source code
Utkarsh Gupta
[][(https://github.com/utkarshgupta-iitbhu)]
[
][(https://www.linkedin.com/in/utkarsh-gupta-iitbhu/)]
A passionate developer learning C++ and building cool projects!