Affine cipher decoder

Turn affine cipher text back into plain text when you know both keys, for puzzles and homework. It is a puzzle cipher that protects nothing.

Loading the tool…

Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.

How to use it

  1. Enter encoded text, multiplier a and shift b.
  2. The result appears straight away and updates as you edit.
  3. Copy the result, or copy a link that keeps the same values to share it.

How it is calculated

Original = a⁻¹ × (y - b) mod 26, where a⁻¹ is the inverse of a, so a × a⁻¹ mod 26 = 1.

Example

Inputs: Multiplier a = 5, Shift b = 8. Result: Decoded text: AFFINE CIPHER; Inverse of a: 21.

IHHWVC SWFRCP
AFFINE CIPHER

Limits and caveats

  • This is a puzzle and teaching cipher that is easy to break, so never use it to protect passwords or sensitive data.
  • You need the same a and b values used to encode.

Questions about this tool

How do I find the inverse of a by hand?

Try 1 to 25 until one gives remainder 1 when multiplied by a and divided by 26. The inverse of 5 is 21, since 105 = 4 × 26 + 1.

What if a = 1?

The cipher becomes a plain Caesar cipher with shift b.

Do spaces stay in place?

Yes. Only Latin letters change; spaces and symbols stay as they are.