Merge monoalphabetic cracking

This commit is contained in:
Smaug123
2016-01-04 21:03:26 +00:00
4 changed files with 171 additions and 4 deletions

View File

@@ -77,6 +77,29 @@ Notice that `encrypt_monoalphabetic` *does not* convert its input to uppercase
when a Dict key is supplied.
It simply makes all specified changes, and leaves the rest of the string unchanged.
Cracking a cipher:
```julia
crack_monoalphabetic(str, chatty=0, rounds=10)
# outputs (key, decrypted_string)
```
The various optional arguments to `crack_monoalphabetic` are:
* `starting_key=""`, which when specified (for example, as "ABCDEFGHIJKLMNOPQRSTUVWXYZ"),
starts the simulation at the given key. The default causes it to start with the most
common characters being decrypted to the most common English characters.
* `min_temp=0.0001`, which is the temperature at which we stop the simulation.
* `temp_factor=0.97`, which is the factor by which the temperature decreases each step.
* `chatty=0`, which can be set to 1 to print whenever the key is updated, or 2 to print
whenever any new key is considered.
* `rounds=1`, which sets the number of repetitions we perform. Each round starts with the
best key we've found so far.
* `acceptance_prob=((e, ep, t) -> ep>e ? 1 : exp(-(e-ep)/t))`, which is the probability
with which we accept new key of fitness ep, given that the current key has fitness e,
at temperature t.
The simulation is set up to start each round off at a successively lower temperature.
### Vigenère cipher
Encrypt the text "Hello, World!" with a Vigenère cipher of key "ab":