Toolgeist › Security
Affine Cipher — Encode/Decode With Two Key Values (a, b)
The Affine cipher encodes each letter using the formula (a·x + b) mod 26, combining a multiplicative key (a) and an additive shift (b) — a generalisation of the Caesar cipher, which is just the special case where a = 1. Key a must be coprime with 26 or the cipher is not reversible.
How to use Affine Cipher
- Paste your text.
- Enter key values a and b.
- Read the encoded or decoded result, with the modular formula shown.
Frequently asked questions
- Why must key a be coprime with 26?
- If a shares a common factor with 26 (2 or 13), the encoding function is not one-to-one — multiple letters map to the same output, making decoding ambiguous or impossible, which is why valid values of a are restricted to those coprime with 26.
- How is this different from a Caesar cipher?
- Caesar is the special case of Affine where a = 1, making it a pure shift; Affine adds a multiplicative component (a) on top, giving more possible keys — 12 valid values of a paired with 26 values of b, versus Caesar's 25.
- Is the Affine cipher secure?
- No — with only a few hundred possible key combinations, it is easily brute-forced and, like other classical substitution ciphers, also vulnerable to frequency analysis. It is an educational stepping stone, not real security.
Related Security tools
Also searched for: affine cipher encoder decoder · affine cipher calculator a b · modular arithmetic cipher tool
Browse all 738 free tools on Toolgeist →