Affine cipher
Encrypt text using the affine cipher, a linear mathematical encryption based on modular arithmetic.
Affine cipher
The affine cipher is a classical encryption method that combines multiplication and addition in modular arithmetic. Each letter is transformed by the formula E(x) = (a*x + b) mod 26, where a and b are your chosen keys and x is the letter's position (0–25). To decrypt, you apply the inverse transformation using the modular multiplicative inverse of a.
Unlike simpler ciphers like Caesar (which only shifts), the affine cipher offers more security through two independent parameters. The multiplier a must be coprime with 26 — meaning it shares no common factors other than 1 — giving you twelve valid choices: 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25. Combined with 26 possible offsets (b), this yields 312 different key combinations, a significant step up from Caesar's 25.
Paste your plaintext and select encode to encipher it, or paste ciphertext and select decode to recover the original. The multiplier controls how letters are scrambled, while the offset shifts them afterward. Capitalization and non-letter characters pass through unchanged. Everything runs in your browser, so your text and keys never leave your device. The live tally shows how many letters were transformed and the total character count.