Implementation of a genetic algorithm to break Vigenère ciphers
See data/
directory
- Activate virtual environment
$ python -m venv .venv
$ source ./.venv/bin/activate
- Build project
$ pip install build
$ python -m build
- Install project
$ pip install dist/geneticalgorithm-0.1.0-py3-none-any.whl
$ pip install tqdm tabulate # (optional) for progress bar and formatting output
$ geneticalgorithm 8 -f attachments/sample.txt -s 3
$ experiment config/sample.json -o csv
$ experiment config/sample.json -v # display all outputs (including decrypted text)
$ experiment config/sample.json -o tbl # requires tabulate package to be installed
$ experiment config/data1.json -o csv > data/data1.csv
$ experiment config/data2.json -o csv > data/data2.csv
To get the list of parameters that can be changed, use:
$ geneticalgorithm --help
For example, to change the crossover algorithm to Order Crossover (OX):
$ geneticalgorithm 8 -f attachments/sample.txt -s 3 --crossover-alg=ox
Or the crossover and mutation rates:
$ geneticalgorithm 8 -f attachments/sample.txt -s 3 -c 0.8 -m 0.05
To change the experiment configurations, edit one of data1.json
, data2.json
, or sample.json
.
A sample configuration file looks like the following:
{
"pop_size": 50,
"max_gen": 20,
"elites": 2,
"seeds": [2, 3],
"runs": [
{
"file": "attachments/sample.txt",
"key_length": 8,
"crossover_algorithms": ["ux", "ox"],
"mutation_algorithms": ["rx", "rc"],
"selection_algorithms": ["tour3"],
"rates": [
{"crossover": 1.0, "mutation": 0.0},
{"crossover": 0.9, "mutation": 0.1}
]
}
]
}
You can run the experiment with this configuration via:
$ experiment /path/to/config.json
For the sample configuration above, this will run the GA for every combination of random seeds, crossover algorithms, mutation algorithms, selection algorithms, and crossover rates.