Skip to content

Instantly share code, notes, and snippets.

@verdi327
Created April 14, 2013 19:31
Show Gist options
  • Save verdi327/5383883 to your computer and use it in GitHub Desktop.
Save verdi327/5383883 to your computer and use it in GitHub Desktop.
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