The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Cipher::Caesar - Simple modular-addition cipher

SYNOPSIS

    my &rot13 := Cipher::Caesar.encipherer;     # Defaults to rot13
    my $julius = Cipher::Caesar.new(:shift(3));
    print rot13("Insert secret here");
    print $julius.cipher("Attack at dawn");

DESCRIPTION

Cipher::Caesar implements simple byte-level modular addition ciphers, including rot13, the Caesar cipher (add or subtract values from all letters), and an unnamed similar cipher where all bytes are changed, not just letters.

Cipher::Caesar conforms to the standard Cipher API; see "Using the Cipher API" in Cipher for general information.

Constructor options

With no options, Cipher::Caesar creates a rot13 encipherer/decipherer (rot13 draws no distinction between them.) The :shift(N) option can be used to select a different number of letters to shift (e.g. Julius Caesar used 3; Augustus Caesar used 1). If a shift is specified, you should also specify either :mode<enciphering> or :mode<deciphering>. The :all option will cause the module to shift across all byte values, not just the ones corresponding to letters.

SECURITY

Caesar ciphers provide extremely trivial security; a cryptanalyst need only graph the letter frequency to crack the cipher, and even if the message is contrived to hide the letter frequency, the keyspace is only 26. You would have to be insane to use this for anything more than obscuring text from accidental viewing. (rot13 in particular is often used for obscuring spoilers, answers, and punchlines.)

SEE ALSO

Cipher

David Kahn, The Codebreakers - The Story of Secret Writing, 1967. ISBN 0684831309.