Created
April 14, 2013 19:31
-
-
Save verdi327/5383883 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Encryptor | |
def cipher(rotation) | |
characters = (' '..'z').to_a | |
rotated_characters = characters.rotate(rotation) | |
Hash[characters.zip(rotated_characters)] | |
end | |
def encrypt_letter(letter,rotation) | |
lowercase_letter = letter.downcase | |
cipher_for_rotation = cipher(rotation) | |
cipher_for_rotation[lowercase_letter] | |
end | |
def encrypt(string, rotation) | |
letters = string.split("") | |
results = [] | |
letters.each do |letter| | |
encrypted_letter = encrypt_letter(letter, rotation) | |
results.push(encrypted_letter) | |
end | |
results.join | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment