EN
My tools

Affine Cipher — Encrypt, Decrypt & Brute Force

Encrypt and decrypt the affine cipher E(x) = (a·x + b) mod 26, with the modular inverse shown, or try all 312 keys ranked by how English the result is.

Must share no factor with 26: 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23 or 25.
Ciphertext
IHHWVC SWFRCP
Modular inverse of a
21
5 × 21 = 105 ≡ 1 (mod 26)
Decryption formula
D(y) = 21 × (y − 8) mod 26
Substitution table: E(x) = (5x + 8) mod 26
PlainxE(x)Cipher
A08I
B113N
C218S
D323X
E42C
F57H
G612M
H717R
I822W
J91B
K106G
L1111L
M1216Q
N1321V
O140A
P155F
Q1610K
R1715P
S1820U
T1925Z
U204E
V219J
W2214O
X2319T
Y2424Y
Z253D
My tools →
Advertisement

The affine cipher maps each letter to a number (A = 0 … Z = 25), multiplies it by a, adds b and takes the remainder after dividing by 26. Caesar (a = 1) and Atbash (a = b = 25) are special cases. This tool encrypts and decrypts with any valid key, shows the modular inverse used for decryption and the full substitution table, and can break a message by trying all 312 keys.

How to use this tool

  1. Choose encrypt, decrypt or the brute-force mode.
  2. Paste the text; case, spaces and punctuation are kept.
  3. Enter a (coprime with 26) and b (0–25), unless you are brute-forcing.
  4. Copy the result, or pick the readable line from the ranked table.

Formula

E(x) = (a·x + b) mod 26 D(y) = a⁻¹·(y − b) mod 26

a⁻¹ is the number that gives a·a⁻¹ ≡ 1 (mod 26); it exists only when a and 26 share no factor, which leaves 12 values of a and 12 × 26 = 312 keys. Brute force decrypts with every key and ranks the results by χ² against English letter frequencies.

Example

With a = 5, b = 8, A (0) → 8 = I, F (5) → 33 mod 26 = 7 = H, so AFFINE CIPHER becomes IHHWVC SWFRCP. The inverse of 5 is 21 (5 × 21 = 105 = 4 × 26 + 1), so decryption is D(y) = 21(y − 8) mod 26.

Frequently asked questions

Why is a = 13 not allowed?

13 shares the factor 13 with 26, so 13·x mod 26 is only ever 0 or 13: every even-numbered letter (A, C, E …) encrypts to the same letter and every odd-numbered one to another, and the message cannot be decrypted. Even values of a fail in the same way. Only a = 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23 and 25 work.

How many affine keys are there?

12 valid values of a times 26 values of b = 312, including the 26 Caesar shifts. That is few enough to try them all, which is why the cipher is easy to break.

How does the brute force rank keys?

Each decryption’s letter counts are compared with English letter frequencies (χ²); the closest comes first. It is reliable from about 40 letters.

Last updated:

Cite or embed this tool
APA

kakaoCalc. (2026, November 8). Affine Cipher — Encrypt, Decrypt & Brute Force. https://kakao.mobile/tools/affine-cipher-tool/

MLA

“Affine Cipher — Encrypt, Decrypt & Brute Force.” kakaoCalc, 8 Nov. 2026, kakao.mobile/tools/affine-cipher-tool/.

Paste this code into your page. The widget runs in your visitors' browsers, shows no ads and keeps a link back to this page. Embedding terms

Advertisement