Ciphers

Caesar

Shift every letter by N. Default 3, keyspace 25, and the attack is all of them.
create
create("caesar")
family
Shift
options
--shift?
self-inverse
no
keyspace
25 (shift 0 is identity)
try it
ciphers caesar "ATTACK AT DAWN" --shift 3

Every letter moves shift places down the alphabet and wraps from Z back to A. Default is 3, the one Suetonius says Caesar used. A shift is an integer from 1 to 25. Zero is the identity and 26 is zero again, both rejected.

import { create } from "@agntn/ciphers";

const caesar = create("caesar");
caesar.encode("ATTACK AT DAWN").text; // "DWWDFN DW GDZQ"
caesar.encode("Hello, World!", { shift: 7 }).text; // "Olssv, Dvysk!"
caesar.decode("DWWDFN DW GDZQ", { shift: 3 }).text; // "ATTACK AT DAWN"

Case survives, punctuation and spaces stay put. Decode with the wrong shift and you get another Caesar, which is why brute force exists: ciphers brute "KHOOR ZRUOG" prints all 25, and shift 3 reads HELLO WORLD.

ROT-13 is this with the shift nailed to 13.

@agntn/ciphers·MIT license· Classical ciphers, for lessons and puzzles. Not for protecting anything, ever.