Skip to content

Instantly share code, notes, and snippets.

@MBM1607
Created February 25, 2021 06:00
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Odin Project Ruby Ceaser Cipher
def caesar_cipher(message, shift)
split_message = message.split("").map do |letter|
# If letter is not an alphabet do not change it
if letter.downcase.ord < 97 or letter.downcase.ord > 128
letter
else
code = letter.ord + shift
if (letter == letter.upcase && code > 90) || (letter == letter.downcase && code > 122)
code -= 26
end
code.chr
end
end
return split_message.join("")
end
puts caesar_cipher("What a string!", 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment