Skip to content

Instantly share code, notes, and snippets.

@ptantiku
Created July 14, 2014 17:26
Show Gist options
  • Save ptantiku/2f2b3fffc92b79bbb9ea to your computer and use it in GitHub Desktop.
Save ptantiku/2f2b3fffc92b79bbb9ea to your computer and use it in GitHub Desktop.
Caesar Cipher
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