JavaScript Caesars Cipher
Requirements
- In Caesars Cipher, also known as Shift Cipher, the meanings of the letters are shifted by a set amount. Implement the ROT13 cipher where the letters are shifted by 13 places. E.g. 'A' becomes 'N', 'B' becomes 'O', etc.
- Accept a ROT13 encoded string and return a decoded string. All letters are assumed to be upper-case.
- Non-alphabetic characters are not decoded but are included in the output string as they are.
Implementation
rot13(str)
decodes a ROT13 cipher encoded string. str
is the ROT13 cipher encoded string. Returns the decoded string.
Example Usage
Use the browser console to interact with the function (Ctrl + Shift + I
, then select the "Console" tab):
> rot13("LBH QVQ VG!"); // YOU DID IT!
> rot13("SERR PBQR PNZC"); // FREE CODE CAMP
> rot13("SERR CVMMN!"); // FREE PIZZA!
> rot13("SERR YBIR?"); // FREE LOVE?