View difference between Paste ID: XUFgtz0R and jZ7MXZZX
SHOW: | | - or go back to the newest paste.
1
def caesar_cipher(str, shift = 5)
2
  alpha = ('a'..'z').to_a
3
  shifted = []
4
5
  str = str.split('')
6
  str.each do |e|
7-
    shifted << if e =~ /[A-Za-z]/
7+
    shifted << case e
8-
                 e == e.downcase ? alpha[alpha.index(e) - shift] : alpha[alpha.index(e)].upcase
8+
               when /[a-z]/
9
                 alpha[alpha.index(e) - shift]
10
               when /[A-Z]/
11
                 alpha[alpha.index(e)].upcase
12
               else
13
                 e
14
               end
15
  end
16
17
  shifted.join
18
end