Created
March 16, 2011 19:20
-
-
Save dpick/873128 to your computer and use it in GitHub Desktop.
Algorithm to decrypt ciphertext created using a vigenere cipher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
key_length = key_length_guess(ciphertext) | |
dot_values, shift_values = [ ], [ ] | |
1.upto(key_length).each do |start_letter| | |
letter_frequency_array = ciphertext.every_nth_letter(key_length, start_letter).letter_frequencies | |
dot_values << letter_frequency_array.dot_product(ENGLISH_FREQUENCIES) | |
1.upto(ENGLISH_FREQUENCIES.size - 1).each do |i| | |
dot_values << letter_frequency_array.dot_product(ENGLISH_FREQUENCIES.rotate!) | |
end | |
ENGLISH_FREQUENCIES.rotate! | |
shift_values << dot_values.find_index(dot_values.max) | |
dot_values = [ ] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment