Caesar Class
The Caesar Cipher is a monoalphabetic substitution cipher, rotating A..Z
and a..z
characters.
Examples using static factory methods:
Caesar.Cipher('c').crypt('ABCD'); // returns: 'CDEF'
Caesar.Decipher('c').crypt('CDEF'); // returns: 'ABCD'
Examples using constructors:
new Caesar( 2).crypt('ABCD'); // returns: 'CDEF'
new Caesar(-2).crypt('CDEF'); // returns: 'ABCD'
new Caesar(24).crypt('CDEF'); // returns: 'ABCD'
See Wikipedia for details.
Constructor
Caesar
(
-
shift
Parameters:
-
shift
NumberThe number to rotate the charCodes
mod 26
and therefore the password of the caesar cipher.
Item Index
Methods
- _rotate
- _substituteCharCode
- Cipher static
- crypt
- Decipher static
Methods
_rotate
(
Number
protected
-
charCode
Return the rotated charCode.
Parameters:
-
charCode
Numberthe charCode to rotate
Returns:
Number:
(charCode + shift) % 26
_substituteCharCode
(
Number
protected
-
charCode
Substitutes only charCodes of A..Z
and a..z
characters.
Parameters:
-
charCode
Numberthe charCode to substitute.
Returns:
Number:
The substituted charCode.
Cipher
(
Caesar
static
-
password
Static factory method to create cipher instances.
Returns:
Caesar:
The Cipher.