Guest User

pull up shifted

a guest
Nov 12th, 2014
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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]/
  8.                  e == e.downcase ? alpha[alpha.index(e) - shift] : alpha[alpha.index(e)].upcase
  9.                else
  10.                  e
  11.                end
  12.   end
  13.  
  14.   shifted.join
  15. end
Advertisement
Add Comment
Please, Sign In to add comment