Productivity and Utilities

Affine and Atbash Cipher Tool

Type a message, choose affine or Atbash and set the key to encrypt or decrypt it.

Your numbers

Action

Letters change; everything else stays. Up to 5,000 characters.

Must have no common factor with 26: 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23 or 25.

A whole number from 0 to 25.

Result

Ciphertext

IHHWVC SWFRCP

Key a = 5, b = 8.

Ciphertext
IHHWVC SWFRCP
Key (a, b)
(5, 8)
Inverse of a mod 26
21

Letter mapping (plain to cipher)

PlainCipher
AI
BN
CS
DX
EC
FH
GM
HR
IW
JB
KG
LL
MQ
NV
OA
PF
QK
RP
SU
TZ
UE
VJ
WO
XT
YY
ZD
How this was calculated
  1. Number the letters A = 0 to Z = 25. Encrypting maps x to (a x + b) mod 26.
  2. Decrypting maps y to a^(-1) (y - b) mod 26, where a^(-1) is the number with a x a^(-1) = 1 mod 26. For a = 5 that is 21.
  3. Only multipliers with no common factor with 26 work, which leaves 12 choices of a and 26 of b, so 312 keys in all.
  • Both ciphers replace each letter by a fixed other letter, so they fall to simple frequency counting. They are for puzzles and classes, not for secrets.

Calculated using SumPanda.com · https://sumpanda.com/affine-and-atbash-cipher-tool/

Results are estimates for general information. Verify important figures before relying on them.

Next step

How to use the affine and atbash cipher tool

  1. Choose Affine or Atbash.
  2. For affine, choose Encrypt or Decrypt, then set the multiplier a and the shift b. The multiplier must have no common factor with 26.
  3. Type or paste the message. Letters change and keep their case; other characters stay as they are.
  4. Read the result and the table showing what each plain letter becomes.

Formula

Number the letters A = 0 to Z = 25

Affine encryption: y = (a x + b) mod 26, with a one of 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25

Affine decryption: x = a^(-1) (y - b) mod 26, where a x a^(-1) = 1 mod 26

Atbash: x becomes 25 - x, so A and Z, B and Y swap; it is affine with a = 25 and b = 25

With 12 allowed values of a and 26 of b there are 312 affine keys. A shift cipher such as Caesar is the case a = 1.

A published affine example and Atbash

With a = 5 and b = 8, the message AFFINE CIPHER becomes IHHWVC SWFRCP. A is 0, so 5 x 0 + 8 = 8, which is I; F is 5, so 25 + 8 = 33, which is 7 mod 26, which is H. Decrypting uses the inverse of 5 modulo 26, which is 21, and returns AFFINE CIPHER.

Atbash turns Wizard Of Oz! into Draziw Lu La!, keeping capital and small letters and the exclamation mark. Applying Atbash again returns the original, because swapping the two ends of the alphabet twice does nothing.

Why a must be coprime to 26

Multiplying by an a that shares a factor with 26 sends two different letters to the same letter. For example a = 2 turns both A (0) and N (13) into A (0), so the message could not be read back. The twelve values that work are the numbers with no factor in common with 26, that is, odd numbers other than 13. The page rejects any other value and explains why.

The inverse of a, used to decrypt, is found with modular arithmetic. For a general calculation of inverses and powers, see the modular arithmetic calculator.

Breaking the ciphers

Both ciphers replace each letter by a fixed other letter, so letter frequencies survive. In English text, the most common letters give away the key quickly. With only 312 keys for affine and a single key for Atbash, a computer tries them all in an instant. Use these ciphers for puzzles, for geocaches and for learning about modular arithmetic.

To count the letters of a ciphertext, use the letter frequency counter. For the plain shift, use the Caesar cipher, and for ciphers that work on pairs of letters, try the Playfair cipher tool or the rail fence cipher tool.

Assumptions and limits

  • Only the 26 letters of the English alphabet are changed; accented letters, digits and symbols are left alone.
  • The multiplier is checked against the 12 allowed values; the shift is 0 to 25.
  • Atbash has no key, and Decrypt is the same as Encrypt.
  • Messages can be up to 5,000 characters.

Formulas reviewed October 10, 2026. See the calculation methodology for how SumPanda rounds, tests and sources its formulas.

Frequently asked questions

What is the affine cipher?

A substitution cipher that turns each letter number x into (a x + b) mod 26. It combines a multiplication with a shift.

Which values of a can I use?

1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23 and 25. These have no common factor with 26, so the cipher can be reversed.

What is Atbash?

A cipher that swaps the alphabet end to end, so A becomes Z, B becomes Y and so on. It is its own inverse.

How is the message decrypted?

Using the inverse of a modulo 26. For a = 5 the inverse is 21, because 5 x 21 = 105 = 1 mod 26.