Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def caesar_cipher(str, shift = 5)
- alpha = ('a'..'z').to_a
- shifted = []
- str = str.split('')
- str.each do |e|
- shifted << case e
- when /[a-z]/
- alpha[alpha.index(e) - shift]
- when /[A-Z]/
- alpha[alpha.index(e)].upcase
- else
- e
- end
- end
- shifted.join
- end
Advertisement
Add Comment
Please, Sign In to add comment