This project uses a Genetic Algorithm to break Vigenere cipher encryption. It evolves populations of candidate keys to find those that produce decrypted text closest to English language patterns, measured by letter frequency analysis.
π Key Features:
- Parallel GA execution with realtime visualization
- Multiple crossover operators (Uniform & PMX)
- Live plotting with progress tables
- Automated result saving and analysis
- π Python 3.7+
- π matplotlib
- π’ numpy
Install dependencies:
pip install matplotlib numpyAll commands run from the project root directory.
Command: python src/main.py
Description: Runs parallel GA experiments with realtime plotting. Tests 5 parameter sets across uniform/PMX crossover and both datasets. Opens matplotlib window with live fitness curves and progress tables. Saves results to timestamped folder in results/.
Runtime: β±οΈ ~10-30 minutes depending on hardware.
Command: python src/test.py
Description: Runs a single GA experiment with easily customizable parameters at the top of the file. Shows realtime plotting of fitness evolution (best and average curves) plus a live table of current generation, best, and average fitness. Saves results and plot to results/Tests/single_[timestamp]/.
Runtime: β±οΈ ~1-5 minutes depending on parameters.
genetic-cryptanalysis/
βββ π data/ # Encrypted datasets
β βββ Data1.txt # 26-char key ciphertexts
β βββ Data2.txt # 40-char key ciphertexts
βββ π src/ # Source code
β βββ main.py # π― Main experiments
β βββ util/ # Utility modules
β βββ evaluation.py # π Fitness functions
β βββ ga.py # 𧬠GA implementation
β βββ rt_plot.py # π Realtime plotting
βββ π results/ # Output files
β βββ experiment_*/ # Timestamped results
βββ π references/ # Assignment materials
βββ .gitignore
Execute the main experiment suite:
python src/main.pyWhat happens:
- π Loads both datasets
- 𧬠Runs GA with 5 parameter sets (a-e)
- π Tests uniform and PMX crossover
- π Displays realtime plots with fitness evolution
- πΎ Saves results to
results/experiment_[timestamp]/
Lower values = better keys (closer to English frequencies)
| Set | Crossover Rate | Mutation Rate | Notes |
|---|---|---|---|
| a | 1.0 | 0.0 | High crossover, no mutation |
| b | 1.0 | 0.1 | High crossover, moderate mutation |
| c | 0.9 | 0.0 | Moderate crossover, no mutation |
| d | 0.9 | 0.1 | Moderate crossover, moderate mutation |
| e | 0.6 | 0.1 | β Optimal (from search) |
- Uniform: Random gene swapping
- PMX: Preserves relative ordering
- Data1: Shorter 26-character keys
- Data2: Longer 40-character keys
Experiment results include:
- π Best chromosomes (decrypted keys)
- π Fitness evolution over generations
- π Comparative performance tables
- πΌοΈ Final plot PNGs
Built by Alaqmar Gandhi for Brock University (COSC 3P71)