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 << if e =~ /[A-Za-z]/
- e == e.downcase ? alpha[alpha.index(e) - shift] : alpha[alpha.index(e)].upcase
- else
- e
- end
- end
- shifted.join
- end
Advertisement
Add Comment
Please, Sign In to add comment