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 | - | if e =~ /[A-Za-z]/ |
7 | + | shifted << if e =~ /[A-Za-z]/ |
8 | - | e == e.downcase ? shifted << alpha[alpha.index(e) - shift] : shifted << alpha[alpha.index(e)].upcase |
8 | + | e == e.downcase ? alpha[alpha.index(e) - shift] : alpha[alpha.index(e)].upcase |
9 | - | else |
9 | + | else |
10 | - | shifted << e |
10 | + | e |
11 | - | end |
11 | + | end |
12 | end | |
13 | ||
14 | shifted.join | |
15 | end |