A Python-based tool for simple image encryption and decryption using the XOR operation. This script allows you to securely encrypt an image file using a user-defined key and later decrypt it using the same key.
- Encrypt and decrypt image files using XOR operations.
- Supports color images in RGB format.
- Easy-to-use interactive command-line interface.
- Ensures that the original image can be fully restored using the same key.
Before running the script, ensure you have the following installed:
- Python 3.6 or later
- Pillow library (
pip install pillow
) - NumPy library (
pip install numpy
)
- Clone this repository:
git clone https://github.com/yourusername/image-encryption-tool.git
- Navigate to the project directory:
cd image-encryption-tool
- Run the script:
python encrypt_decrypt_image.py
- Follow the prompts:
- Provide the path to the input image.
- Specify the output path for the encrypted/decrypted image.
- Enter an encryption key (integer between 0 and 255).
-
Encryption/Decryption:
- The script applies the XOR operation (
^
) between the image pixel values and the encryption key. - The same key can be used to decrypt the encrypted image back to its original form.
- The script applies the XOR operation (
-
Key Restrictions:
- The encryption key must be an integer between 0 and 255 to ensure compatibility with RGB pixel values.
-
Image Support:
- Supports any image format that can be opened by the
Pillow
library and converts it to RGB.
- Supports any image format that can be opened by the
Input Image: input_image.jpg
Output (Encrypted): encrypted_image.jpg
Output (Decrypted): decrypted_image.jpg
Encryption key: 123
The script includes basic error handling for:
- Invalid file paths.
- Unsupported file formats.
- Out-of-range or invalid encryption keys.
Contributions are welcome! If you encounter issues or have ideas for improvement, feel free to open an issue or submit a pull request.