Created
August 26, 2016 14:50
-
-
Save romerobrjp/985d121d010daa974bf4fdc998446460 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
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