Skip to main content

Affine Cipher

Encode and decode the affine cipher with keys a and b, and try all valid keys to break a message. Explains why a must be coprime with 26. Free and private.

More options

This is not secure encryption: anyone can break it. Use AES encryption for real secrets.

Shortcuts: Ctrl+Enter run · Ctrl+Shift+C copy result · / search (use ⌘ on Mac)

Free Affine Cipher

Each letter number x becomes (a × x + b) mod 26. The number a must have no common factor with 26, or the message cannot be decoded. It gives developers a quick browser-based way to solve a focused affine cipher task before moving the result into a project.

How to use Affine Cipher

Choose a and b. To break a message without the key, put it in the box with Decode selected: the best keys are listed below.

Common mistakes

  • Using an even a or 13: it cannot be decoded.
  • Using a very short text for the key search: the best score is unreliable.

Frequently asked questions

Why must a be coprime with 26?
If a shares a factor with 26, two letters would map to the same letter and the message could not be decoded. The 12 allowed values are 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23 and 25.
How many keys are there?
12 values of a and 26 values of b give 312 keys, one of which (a = 1, b = 0) changes nothing.
Is it secure?
No. It has few keys and keeps letter frequencies, so it is easy to break.
Is anything uploaded?
No. The calculation runs in your browser and nothing you enter is sent to a server.
How do I use this affine cipher tool?
Use the interactive controls above; processing stays in your browser and the result is intended as a practical starting point for development work.

More Security & Auth

View all Security & Auth tools →