Affine Cipher Encrypt & Decrypt

Linear substitution cipher: E(x) = (ax + b) mod 26.

Ad placeholder (leaderboard)

The Affine cipher is a monoalphabetic substitution cipher in which each letter is mapped to a number, transformed by a simple linear function, and mapped back to a letter. It combines a multiplicative key and an additive key, making it more flexible than a plain Caesar shift while remaining easy to understand. This tool encrypts and decrypts text instantly in your browser with no upload.

How it works

Convert each letter to a number with A=0 through Z=25. Encryption applies the function E(x) = (a·x + b) mod 26, where a is the multiplicative key and b is the additive key. The result is mapped back to a letter.

Decryption reverses this with D(y) = a⁻¹·(y − b) mod 26, where a⁻¹ is the modular multiplicative inverse of a modulo 26. For the inverse to exist, a must be coprime with 26, so the tool only offers the valid values 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23 and 25.

Example

With a = 5 and b = 8, encrypt the letter A (x = 0): (5·0 + 8) mod 26 = 8, which is the letter I. Encrypting the phrase AFFINE CIPHER produces IHHWVC SWFRCP. Decrypting uses a⁻¹ = 21 (since 5·21 = 105 ≡ 1 mod 26) to recover the original text.

Notes

There are 12 valid choices for a and 26 for b, giving 312 possible keys — small enough to break by brute force. Because letter frequencies are preserved, the Affine cipher is also vulnerable to frequency analysis on longer messages.

Ad placeholder (rectangle)