Ciphers

Ciphers

Eighteen ciphers in eight families. Each page has the options, the keyspace, the conventions and a vector you can check yourself.

Every cipher answers encode and decode with the same CipherResult. What changes is the alphabet it works on, the options it needs, and the small decisions that make a puzzle answer reproducible - which letters share a cell, what happens to a doubled pair, whether a space survives. Those decisions are the part nobody documents, so each page here does.

CipherFamilyOptionsSelf-inverseKeyspace
Caesarshiftshift25
ROT-13shift1
ROT-47shift1
Atbashreflection1
Affinemultiplicativea, b312
Vigenèrepolyalphabetickey26^key length
Trithemiuspolyalphabeticfixed
Albertipolyalphabetickey, periodkeyed disk × period
Playfairdigraphkey25!
Polybiusfractionationkey optional1 or 25!
Morsefractionation1
Baconfractionation1
Tap codefractionation1
ADFGVXfractionationkey optional36! or keyed
Bifidfractionationkey optional, period25! × period
Rail fencetranspositionrails~n
Columnartranspositionkeyn!
Enigma M3rotorpositions, rings, plugboard26^6 × plugboard

Conventions shared by all

  • Latin alphabets are A to Z. Digits, punctuation, emoji and non-Latin letters pass through untouched unless stripNonAlpha is set, and they never advance a key.
  • preserveCase is on by default. Lowercase in, lowercase out.
  • Playfair, Polybius and Bifid fold J into I. Tap code shares C and K. Bacon uses 26 letters, not the historical 24. Enigma is the Wehrmacht M3 with rotors I, II, III and reflector B.
  • Shift 0, one rail, a multiplier sharing a factor with 26 - an option that would make the cipher an identity or break the bijection is an error before the first letter. No silent pass.

Families

Shift adds a constant to every letter. Reflection mirrors the alphabet. Multiplicative multiplies and adds modulo 26. Polyalphabetic changes the shift as it goes - by keyword, by position, or by turning a disk. Digraph works on pairs. Fractionation breaks a letter into coordinates or symbols and, in Bifid and ADFGVX, shuffles the pieces. Transposition moves letters without changing them. Rotor has one member, and that one has enough settings for the rest.

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