I'm creating a caesar cipher in Ruby based on the code from Rosetta Code, but my code only prints the original word, rather than the modified word.
Here's my code:
class String
ALPHABET = ("A".."Z").to_a
def caesar_cipher(num)
self.tr(ALPHABET.join, ALPHABET.rotate(num).join)
end
end
word = gets.chomp.to_s
encypted = "#{word}".caesar_cipher(8)
decrypted = "#{word}".caesar_cipher(-8)
puts "Encrypt or Decrypt?"
choice = gets.chomp.to_s.downcase
if choice == "encrypt"
puts encypted
elsif choice == "decrypt"
puts decrypted
else
puts "Invalid option"
end
Any help would be greatly appreciated!