You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
11 lines
270 B
Ruby
11 lines
270 B
Ruby
5 years ago
|
LOWER_Z = 122
|
||
|
|
||
|
def caesar_cipher(text, shift)
|
||
|
ciphered_text = ''
|
||
|
shift = shift % LOWER_Z
|
||
|
text.each_char do |letter|
|
||
|
ciphered_text += letter.ord + shift > LOWER_Z ? (letter.ord + shift - LOWER_Z).chr : (letter.ord + shift).chr
|
||
|
end
|
||
|
ciphered_text
|
||
|
end
|