Challenge 40

🤴

"Encryption" - Caesar Cipher

Open in Code Editor or Copy Instructions

During the Roman empire, Julius Caesar

In this encryption algorithm, a shift amount is required - for example, if the shift amount is 3, then each character would be shifted 3 places. See below for examples:

You should implement functions to both encrypt and decrypt

Spaces should remain unchanged

Examples:

encrypt("ab c de", 1) would return "bc d ef"

decrypt("bc d ef", 1) would return "ab c de"

encrypt("abc", 3) would return "def"

decrypt("def", 3) would return "abc"

encrypt("xyz", 3) would return "{|}"

decrypt("{|}", 3) would return "xyz"

Note: in this simple example, wrap-around isn't required

Extension:

Implement wrap-around - i.e. after reaching z, we go back to a. This should work for both uppercase and lowcase letters. For example encrypt("xyz XYZ") should return "abc ABC"

Add support for signed numbers - i.e. "FF" would no longer be 255...but now -1