This application is used to encrypt and decrypt images using the Hill Cipher algorithm. It provides an easy-to-use graphical user interface (GUI) for everyone, as well as a command-line interface (CLI) for advanced users.
- Encrypt images using the Hill Cipher method
- Decrypt encrypted images
- Supports both color and grayscale images
- Generate your own encryption key
- Available as both GUI and CLI
- Windows .exe version available
This application is suitable for:
- Beginners who want to try encrypting images easily
- Non-IT users who want to protect their image privacy
- Anyone interested in learning about simple encryption
- Download and run the
HillCipherImageTool.exefile (see the download link below). - Once the app opens, select the image you want to encrypt or decrypt.
- Choose the operation (Encrypt/Decrypt).
- Select or create a key file.
- Click the process button, then save the result.
If you want to run it with Python:
- Make sure Python is installed on your computer.
- Install the dependencies with the command:
pip install -r requirements.txt
- Run the GUI application:
python main.py
- For CLI (command-line) mode:
python main.py --cli encrypt input.png output.png key.json python main.py --cli decrypt encrypted.png decrypted.png key.json
Download the Windows version of the application here: Download HillCipherImageTool.exe
If you have questions or want to contribute, please open an issue in this repository.
Happy trying and hope it is useful!
A user-friendly implementation of Hill Cipher for image encryption using Python and cryptography.
This project implements the Hill Cipher algorithm for encrypting and decrypting digital images. It provides a comprehensive graphical user interface designed for both technical and non-technical users.
- Image Encryption/Decryption: Secure Hill Cipher implementation for various image formats
- Key Management: Generate, save, load, and manually enter encryption keys
- User-Friendly GUI: Intuitive interface designed for non-IT users
- Multiple Image Formats: Support for PNG, JPEG, BMP, TIFF, and GIF
- Progress Tracking: Real-time progress indicators for operations
- Statistical Analysis: Compare original vs encrypted images
- Histogram Visualization: Visual comparison of pixel distributions
- Entropy Calculation: Measure encryption randomness and quality
- Correlation Analysis: Evaluate encryption effectiveness
- Invertible Key Generation: Ensures reliable decryption
- Metadata Preservation: Maintains encryption parameters
- Key Validation: Verifies key matrix validity
- Secure Random Key Generation: Uses cryptographically secure methods
- Python 3.13 or higher
- Required packages listed in
requirements.txt
-
Clone or download the project
cd path/to/hill-cipher-program -
Install required packages
pip install -r requirements.txt
-
Run the application
python main.py
-
Select Input Image
- Click "Browse" to select your image file
- Use "Preview" to view the selected image
- Supported formats: PNG, JPEG, BMP, TIFF, GIF
-
Set Encryption Key
- Generate Random Key: Creates a secure random key matrix
- Load Key from File: Use a previously saved key
- Enter Manually: Input your own key matrix
-
Choose Output Location
- Click "Browse" to select where to save the encrypted image
- The tool automatically saves encryption metadata
-
Encrypt
- Click "Encrypt Image" to start the process
- Save the key file for later decryption!
-
Select Encrypted Image
- Browse and select the encrypted image file
-
Load Decryption Key
- Load the key file used for encryption
- Or use the currently loaded key
-
Choose Output Location
- Select where to save the decrypted image
-
Decrypt
- Click "Decrypt Image" to restore the original
- Navigate to "Key Management" tab
- Select key matrix size (2x2, 3x3, or 4x4)
- Click "Generate Random Key"
- Larger matrices provide stronger encryption
- Enter matrix values in the text area
- Format: one row per line, space-separated values
- Example for 2x2 matrix:
3 2 5 7
- Save keys to JSON files for future use
- Load previously saved keys
- Keys contain matrix data and metadata
- Compare original and encrypted images
- View pixel value statistics
- Calculate correlation coefficients
- Assess encryption quality
- Visual comparison of pixel distributions
- Side-by-side histogram display
- Supports both color and grayscale images
- Measure image randomness
- Higher entropy indicates better encryption
- Maximum entropy: 8.0 bits per pixel
The Hill Cipher is a polygraphic substitution cipher based on linear algebra. For images:
- Key Matrix: An n×n invertible matrix (mod 256)
- Block Processing: Image pixels are processed in blocks
- Encryption: C = (K × P) mod 256
- Decryption: P = (K⁻¹ × C) mod 256
Where:
- K = Key matrix
- P = Plaintext block
- C = Ciphertext block
- K⁻¹ = Inverse key matrix
- Modular arithmetic (mod 256 for 8-bit images)
- Matrix inversion using extended Euclidean algorithm
- Determinant calculation and GCD verification
- Multi-channel support (RGB, RGBA, Grayscale)
- Proper padding for block alignment
- Metadata preservation for reliable decryption
- Key matrix invertibility verification
- Cryptographically secure random generation
- Correlation analysis for encryption validation
hill-cipher-program/
├── hill_cipher.py # Core Hill Cipher implementation
├── gui_application.py # GUI application
├── requirements.txt # Python dependencies
├── README.md # This file
└── sample_images/ # Test images (if any)
-
"Matrix not invertible" error
- Generate a new random key
- Ensure manual keys have non-zero determinant
-
"Import error" messages
- Install required packages:
pip install -r requirements.txt - Verify Python version (3.13+)
- Install required packages:
-
Decryption produces noise
- Verify correct key is loaded
- Check if metadata file exists
- Ensure same key used for encryption
-
Large file processing slow
- Normal for large images
- Progress bars show operation status
- Consider using smaller images for testing
- Use 2x2 keys for faster processing
- PNG format recommended for lossless encryption
- Close other applications for better performance
This project demonstrates:
- Linear Algebra: Matrix operations and modular arithmetic
- Cryptography: Symmetric encryption principles
- Image Processing: Digital image manipulation
- Software Engineering: GUI design and user experience
- Mathematical Analysis: Statistical and entropy analysis
- Block Cipher: Patterns may be visible in uniform areas
- Key Security: Requires secure key distribution
- Processing Time: Large images take longer to process
- Lossless Only: Works best with lossless image formats
Potential improvements:
- Batch processing capabilities
- Advanced key derivation functions
- Support for video encryption
- Network-based key sharing
- Enhanced statistical analysis
This project is created for educational purposes. Use responsibly and in accordance with applicable laws and regulations.
For questions or issues related to this implementation, please refer to the documentation or create an issue in the project repository.