Last active
March 16, 2016 01:20
-
-
Save jblakeman/287d248ace57f6e3aad6 to your computer and use it in GitHub Desktop.
Vignere Cipher Encryption
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
def vignere(message, keyword) | |
min_byte = 97 | |
max_index = 26 | |
cipher = "" | |
message.downcase.split("").each_with_index do |char, i| | |
cipher_i = (char.ord - min_byte) + (keyword[i].ord - min_byte) | |
cipher_i -= max_index if cipher_i > max_index | |
cipher += (cipher_i + min_byte).chr | |
end | |
cipher | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment