Affine Cipher

Only these 12 values can be undone.

0 to 25.

Results

Letter mapping (encoding)
Plain
Cipher

The affine cipher numbers the letters A = 0 to Z = 25, multiplies each by a key a, adds a key b and wraps around at 26. It sits between the Caesar cipher (a = 1, a pure shift) and Atbash (a = 25, b = 25, the alphabet reversed). With only 312 possible keys, it is a classic exercise in modular arithmetic rather than real protection.

How to use it

  1. Choose Encode or Decode.
  2. Type the text.
  3. Pick key a and key b; the result and the letter mapping update as you type.

Examples: with a = 5 and b = 8, AFFINE CIPHER becomes IHHWVC SWFRCP, and decoding it brings back AFFINE CIPHER. With a = 25 and b = 25, HELLO becomes SVOOL, exactly as in Atbash.

Questions and answers

Why can't a be any number?

To decode, you multiply by the inverse of a modulo 26, and only numbers sharing no factor with 26 have one: 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23 and 25. With a = 2, for example, A and N would both become the same letter.

How is it broken?

Each letter always maps to the same letter, so letter frequencies give it away: the most common cipher letter is probably E. Two known letters are enough to solve for a and b, and trying all 312 keys takes a computer no time at all.

What happens to spaces, digits and accents?

Only the letters A to Z are changed, in upper and lower case. Everything else is kept as it is.

Link with pre-filled values

Add # and these parameters to the end of this page's address to open the tool with values already filled in.

ParameterWhat it sets
textText to encode or decode.
aMultiplier key: 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23 or 25.
bShift key, 0 to 25.
modeencode or decode.

Example: https://toolabelle.com/affine-cipher/#text=AFFINE+CIPHER&a=5&b=8&mode=encode

Related tools