caesar-salad

API Docs for: v2.0.1
Show:

Caesar Class

Defined in: caesar.js:6
Module: caesar-salad

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
)

Defined in caesar.js:6

Parameters:

  • shift Number

    The number to rotate the charCodes mod 26 and therefore the password of the caesar cipher.

Item Index

Methods

_rotate

(
  • charCode
)
Number protected

Defined in caesar.js:33

Return the rotated charCode.

Parameters:

  • charCode Number

    the charCode to rotate

Returns:

Number:

(charCode + shift) % 26

_substituteCharCode

(
  • charCode
)
Number protected

Inherited from SubstitutionCipher but overwritten in caesar.js:45

Substitutes only charCodes of A..Z and a..z characters.

Parameters:

  • charCode Number

    the charCode to substitute.

Returns:

Number:

The substituted charCode.

Cipher

(
  • password
)
Caesar static

Defined in caesar.js:68

Static factory method to create cipher instances.

Parameters:

Returns:

Caesar:

The Cipher.

crypt

(
  • input
)
Number
Template method to encrypt/decrypt strings substituting its input charCode by charCode.

Parameters:

  • input String
    The string to process.

Returns:

Number: The processed string.

Decipher

(
  • password
)
Caesar static

Defined in caesar.js:80

Static factory method to create decipher instances.

Parameters:

Returns:

Caesar:

The Decipher.