How does the affine cipher work?
Each letter gets a number, from 0 for A to 25 for Z. It is replaced by the letter numbered a × x + b, keeping the remainder after division by 26. With a = 5 and b = 8, “AFFINECIPHER” becomes “IHHWVCSWFRCP”.
So that two letters never give the same one, a must share no divisor with 26: it can only be 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23 or 25. When a is 1 you are back to the Caesar cipher.
Decrypting
You subtract b, then multiply by the inverse of a modulo 26. Enter both numbers and paste the message into the second box: the plain text appears.
Finding an unknown key
There are only 312 keys, one of which changes nothing. The tool tries the other 311 and ranks the results by comparing letter frequencies with those of the page language. The “Use” button applies a suggestion. With a very short message the right answer may sit lower down, or be missing from the list.
An exercise, not a protection
The affine cipher is a classic of modular arithmetic lessons. It protects no data: use modern encryption such as AES for that.
Frequently asked questions
Why is a = 2 not allowed?
Because A and N would give the same letter: decrypting would become impossible.
What is the inverse of a?
The number which, multiplied by a, leaves a remainder of 1 after division by 26. For 5 it is 21.
Are accents and digits encrypted?
No, only the letters A to Z change, unless you remove accents before encrypting.
Is my message sent anywhere?
No. Everything is computed in your browser.
How can I check a result by hand?
Take the first letter, count its rank from zero, multiply by a, add b, then subtract 26 as often as needed. The rank you get names the encrypted letter. With a = 5 and b = 8, F, rank 5, gives 33, that is 7: an H.