Function Codes Ciphers Class

CaesarCipher

Encode or decode a message using the Caesar Cipher.

Signature (Visual Basic / VBA)

Public Function CaesarCipher( _
      ByVal vMessage As Variant _
    , Optional ByVal vOffset As Variant _
    , Optional ByVal vAlphabet As Variant _
    ) As Variant

Code Example

    CaesarCipher("ATTACK AT DAWN",  3, CryptoAlphabet) = "DWWDFNCDWCGDZQ"
    CaesarCipher("DWWDFNCDWCGDZQ", -3, CryptoAlphabet) = "ATTACK AT DAWN"

Parameters

Parameter Description
vMessage String containing the message which is to be either encoded or decoded using the Caesar Cipher. Function returns Null if vMessage is Null or cannot be fixed up to a String.
vOffset Number of character positions that each character within the message should be translated after being looked-up in the alphabet string. With an alphabet of "ABCDEFGHIJKLMNOPQRST" and an offset of 3 (three), "ABCDEF" would become "DEFGHI". vOffset defaults to 3 (three) if it is missing or Null or cannot be fixed up to a number.
vAlphabet String containing the alphabet of characters which is used to encipher or decipher the message. vAlphabet defaults to every character within the character set if it is missing or Null or cannot be fixed up to a String. Function returns Null if vAlphabet is an empty string.

Notes & Version History

Summary The Caesar Cipher works by replacing each character by the one that is some specific number of positions ahead of it within the alphabet.
Note Use a positive Offset to encipher (encode) and a negative Offset to decipher (decode).
Note This function will work if the characters in vAlphabet are not in sorted order, but the alphabet should be sorted for the operation to be considered a Caesar Cipher.
Note Any characters in the message string vMessage which do not appear within the alphabet string vAlphabet will be ignored.