Created
July 14, 2014 17:26
-
-
Save ptantiku/2f2b3fffc92b79bbb9ea to your computer and use it in GitHub Desktop.
Caesar Cipher
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 shift(str, n) | |
before = [*'a'..'z'].join | |
after = [*'a'..'z'].rotate(n).join | |
str = str.tr(before, after).tr(before.upcase, after.upcase) | |
return str | |
end | |
str = 'Myxqbkdevkdsyxc, iye wkno sd!!' | |
26.times{|i| | |
puts "#{i}: #{shift(str,i)}" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment