Skip to content

Instantly share code, notes, and snippets.

@romerobrjp
Created August 26, 2016 14:50
Show Gist options
  • Save romerobrjp/985d121d010daa974bf4fdc998446460 to your computer and use it in GitHub Desktop.
Save romerobrjp/985d121d010daa974bf4fdc998446460 to your computer and use it in GitHub Desktop.
def rot13(secret_messages)
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz '.split('')
rot13 = 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm '.split('')
lookup_hash = {}
alphabet.zip(rot13) do |key, value|
lookup_hash[key] = value
end
secret_messages = ["qrygn", "zrrg ng pubpbyngr pbeare", "gra zra", "gjb onpxhc grnzf", "zvqavtug rkgenpgvba"]
decoded_phrase = []
secret_messages.map do |word|
splitted_word = word.split('')
decoded_word = ""
splitted_word.map do |char|
decoded_word << lookup_hash[char] if lookup_hash.has_key? char
end
decoded_phrase << decoded_word
end
decoded_phrase
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment