A Flask-based web application that implements hybrid cryptographic techniques optimized using Genetic Algorithms for both text and image encryption/decryption.
- Upload images in various formats (JPG, PNG, etc.)
- Encrypt images using GA-optimized keys
- Decrypt encrypted images to recover original content
- Download processed images
- Visual comparison of original, encrypted, and decrypted images
- Encrypt text messages using Vigenère cipher with GA-optimized keys
- Decrypt encrypted text back to original plaintext
- Simple textarea-based interface
- Automatic key generation using Genetic Algorithm
- Population-based search for optimal encryption keys
- Fitness evaluation based on encryption quality
- Evolution over multiple generations for key improvement
Hybrid_Crypto_GA/
β
βββ app.py # Flask backend (main application)
βββ encryption.py # Encryption/decryption logic
βββ genetic_algorithm.py # GA optimization implementation
β
βββ static/
β βββ uploads/ # Temporary uploaded images
β βββ results/ # Encrypted/decrypted images
β
βββ templates/
βββ index.html # Frontend user interface
Make sure you have Python 3.7+ installed on your system.
- Clone the repository
git clone https://github.com/Jay121305/Hybrid-Image-Encryption-using-Genetic-Algorithm-.git
cd Hybrid_Crypto_GA- Install required dependencies
pip install flask pillow numpy- Start the Flask server
python app.py- Open your browser and navigate to
http://localhost:5000
- The application will run the Genetic Algorithm optimization on startup (this may take a moment)
- Initialization: Random population of encryption keys is generated
- Fitness Evaluation: Each key is evaluated based on encryption quality
- Selection: Best-performing keys are selected for reproduction
- Crossover: Selected keys are combined to create offspring
- Mutation: Random modifications introduce diversity
- Evolution: Process repeats for multiple generations
- Convergence: Optimal keys are identified and used for encryption
The GA typically runs for 40-50 generations, continuously improving the encryption key quality.
- Image Encryption: Pixel-level manipulation using the GA-optimized image key
- Text Encryption: Vigenère cipher using the GA-optimized text key
Original image is transformed into encrypted noise pattern
Encrypted image is successfully recovered to original form
Encrypted Text:
Plain text: "HELLOWORLD" β Encrypted: "WEDRDWGXAD"
Decrypted Text:
Encrypted text is successfully decrypted back to: "HELLOWORLD"
The platform features a modern, dark-themed interface with:
-
Image Encryption/Decryption Section (Blue accent)
- File upload with visual feedback
- Encrypt/Decrypt dropdown selector
- Result display with download option
- Success/error notifications
-
Text Encryption/Decryption Section (Purple accent)
- Textarea for text input
- Encrypt/Decrypt dropdown selector
- Result display area
- Success/error notifications
- Population Size: 20 individuals
- Generations: 40-50 iterations
- Mutation Rate: Configurable
- Selection Method: Tournament/Fitness-based
- Crossover: Single/Multi-point
- Image Key: Generated by GA for pixel manipulation
- Text Key: Generated by GA for Vigenère cipher
- Key Space: Large enough to ensure security
The GA optimization typically shows:
- Initial Best Fitness: 0.40-0.50
- Final Best Fitness: 0.95-0.99
- Average Fitness Improvement: Consistent increase over generations
- Convergence: Usually within 30-40 generations
Example GA output:
Running GA β this may take a bit...
Gen 0 | Best: 0.9700 | Avg: 0.3650
Gen 5 | Best: 0.9800 | Avg: 0.8680
Gen 10 | Best: 0.9900 | Avg: 0.7965
Gen 15 | Best: 0.9900 | Avg: 0.9325
...
Gen 40 | Best: 0.9900 | Avg: 0.8990
- Keys are generated using genetic algorithm optimization
- Image encryption uses pixel-level manipulation
- Text encryption uses Vigenère cipher (educational purposes)
- Note: This is an educational project. For production use, consider implementing AES, RSA, or other industry-standard algorithms.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Add more encryption algorithms (AES, RSA)
- Implement encryption strength metrics
- Add batch processing for multiple images
- Visualize GA evolution process with graphs
- Export encryption keys securely
- Add password-based key derivation
- Support for more file formats (PDF, DOCX)
Jay Gautam - @Jay121305
This project is licensed under the MIT License - see the LICENSE file for details.
- Genetic Algorithm concepts and implementation
- Flask framework for web development
- Pillow library for image processing
- Cryptographic principles and hybrid encryption techniques
For questions or feedback, please open an issue on GitHub or contact the repository owner.
β Star this repository if you found it helpful!
π Made with β€οΈ using Python, Flask, and Genetic Algorithms

