A common modern use of the simplest and most widely known ciphers, Caesar cipher, is the ROT13 cipher, where the values of the letters are shifted by 13 places.
Thus 'A' ↔ 'N', 'B' ↔ 'O' and so on.
The rot13()
function takes a ROT13 encoded string as input and returns a decoded string. All letters must be uppercase.
The CaesarCryptoCoder()
function takes a string of characters and a shift value. It uses double length alphabet, including all lower case and upper case characters: a-zA-Z
.
The CaesarsCipher
class should be instantiated with new
provided a shift
value. The instance can be used to encode/decode strings. Resulting string letters are converted to upper case after encoding/decoding.