Skip to content

gideonoludeyi/vigenere-geneticalgorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Breaking Vigenère Ciphers /w Genetic Algorithm

Implementation of a genetic algorithm to break Vigenère ciphers

Generated Data

See data/ directory

Build

  1. Activate virtual environment
$ python -m venv .venv
$ source ./.venv/bin/activate
  1. Build project
$ pip install build
$ python -m build
  1. Install project
$ pip install dist/geneticalgorithm-0.1.0-py3-none-any.whl
$ pip install tqdm tabulate # (optional) for progress bar and formatting output

Usage

Run Genetic Algorithm

$ geneticalgorithm 8 -f attachments/sample.txt -s 3

Run experiment

$ 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

Reproducing data/data1.csv and data/data2.csv

$ experiment config/data1.json -o csv > data/data1.csv
$ experiment config/data2.json -o csv > data/data2.csv

Changing Parameters (geneticalgorithm)

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

Changing Parameters (experiment)

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.

About

breaking Vigenère ciphers with GAs

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages