Encrypting and Decrypting a message
In cryptography, character shifting encryption, or Caesar cipher, is used by Julius Caesar who led the Roman Empire.
For example, the character E shifted backwards by 3 characters would be B.
So, the word "Hello" with each character shifted backwards by 3 characters would be "khoor".
Use String methods .ord
to convert find the integer ordinal of a string and .chr
to convert integer ordinal back to string.
> "H".ord
> # => 72
> 72.chr
> # => "H"
Your assignment
- Write a function to encrypt a message (by shifting char code up or down)
- Write a function to decrypt a message
Example:
encrypt("hello")
# => "ifmmp"
decrypt("ifmmp")
# => "hello"
def encrypt(message)
# your answer
end
def decrypt(message)
# your answer
end