What is a Affine Cipher?
The affine cipher turns each letter into a number, multiplies it, adds a shift, and wraps the result back into the alphabet. It is the cipher teachers use to show modular arithmetic doing real work. It works entirely in your browser: you type or paste text, and the result appears at once, with nothing uploaded and nothing stored. People searching for a affine cipher usually want exactly that — a quick answer without an account, a download, or a wait.
Maths students meeting modular arithmetic for the first time, puzzle fans who want a cipher with a key, and teachers who need a worked example where the maths is visible in every step. Students use it for homework and puzzles, developers use it at work, and writers use it when a deadline is close. The common thread is simple: the job is small, the answer should be instant, and the text should stay private.
This page keeps that promise. The affine Cipher runs on your own device, so your words never leave the tab. You can use it as often as you like, on any text, and close the page knowing nothing was saved anywhere — there is no history, no log, and no sign-up standing between you and the answer.
If you have never used a tool like this before, start with the example on this page and change one thing at a time — one word, one setting — and watch the result change. That is the fastest way to learn what each input does, and it works for every tool in this family, because they all follow the same pattern: text in, result out, nothing saved.
How a Affine Cipher works
Letters become numbers first: A is 0, B is 1, through to Z at 25. Encryption computes (a times x plus b) mod 26, where a is the multiplier and b is the shift. Decryption needs the modular inverse of a — the number that, multiplied by a, leaves remainder 1 when divided by 26 — and computes the inverse times (x minus b) mod 26. That is why a must be coprime to 26: only the twelve values 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, and 25 have an inverse. The rule this page uses is: Each letter x becomes (a times x plus b) mod 26, where a must be coprime to 26. Decryption uses the modular inverse of a.
With only 12 valid values of a and 26 of b, there are just 312 possible keys, so a computer tries them all instantly and a patient person can try them by hand. The cipher also keeps letter frequencies, so an 'e' in the message still shows up as the most common letter in the ciphertext.
Because the rule never changes, the same input always gives the same output. Run the example below twice and the result will match exactly, character for character. That predictability is what makes the tool useful for checking your own work. For a different kind of text job, the text reverser covers the next step once you have your result. The comparison section further down this page explains which of the two fits which job, so you can pick before you paste.
The rule above is the whole method — there is no hidden step and no second pass. What you see in the rule is what the tool computes, which is why the worked example below can be followed by hand, one step at a time, with a pencil if you like.
The value of a, explained
The value of a is the multiplier, and it must share no factor with 26 — it must be coprime to 26. That leaves twelve choices: 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, and 25. Any other value has no modular inverse, which means the cipher cannot be decrypted, and this tool will tell you the key is invalid.
With a=5 and b=8, H (7) becomes 5 times 7 plus 8, which is 43, and 43 mod 26 is 17, which is R. The whole word HELLO becomes RCLLA. Note that a=1 turns the cipher into a plain Caesar shift by b, which is a useful check that the formula is working.
If you are setting a puzzle, avoid a=1 — it is just a Caesar shift and solvers will spot it at once. Values like 5, 7, 11, and 17 scramble the alphabet thoroughly while staying easy to work with by hand.
When in doubt, try the worked example below first — it uses the page defaults, so it shows the tool working exactly as it ships.
Paste from anywhere — a document, a chat, a web page. The tool reads only the text you give it, so stray formatting, links, and images are left behind. If the pasted text looks odd, paste it as plain text first and then copy it in, so nothing invisible rides along.
A worked example
Take this input: 'HELLO' with a=5 and b=8. H (7) becomes 5x7+8=43, 43 mod 26=17=R. E (4) becomes 5x4+8=28, 28 mod 26=2=C. L (11) becomes 5x11+8=63, 63 mod 26=11=L. The second L repeats, and O (14) becomes 5x14+8=78, 78 mod 26=0=A. The result is 'RCLLA' — 5 characters, with the key check reading 'Valid key'.
Decrypt 'RCLLA' with the same key: the inverse of 5 mod 26 is 21, because 5 times 21 is 105 and 105 mod 26 is 1. R (17) becomes 21 times (17-8), which is 189, and 189 mod 26 is 7, which is H. The rest follow the same way.
Try a=3, b=0 on 'ABC': A (0) stays A, B (1) becomes 3, which is D, and C (2) becomes 6, which is G — so 'ABC' becomes 'ADG'. The spacing between letters triples, which shows what the multiplier does on its own.
You can check the result yourself without trusting the page. Reverse the operation — decrypt what you encrypted, or run the output back through the tool with the opposite setting — and the original input should come back. If it does not, the first thing to check is the input: a missing letter, an extra space, or a setting that changed between the two runs.
Who uses a Affine Cipher — and why
A maths teacher sets a homework where students encrypt their own name with a=5, b=8 and then decrypt a classmate's message, so modular inverses stop being abstract. It is the kind of job that comes up often enough to remember, and rarely enough to justify installing anything for.
A puzzle maker uses an affine cipher as the second stage of a hunt, after solvers have already cracked a Caesar shift and are ready for a key with two parts. The case converter is the natural next stop when the result needs a different treatment. It answers the question this page leaves open, so the two together cover the whole job.
A student preparing for a cryptography exam checks their hand calculations against this tool before trusting them.
Affine Cipher vs ROT13 Encoder
The ROT13 encoder is a fixed shift of 13, which is a special case of the affine cipher with a=1 and b=13, while the affine cipher multiplies as well as shifts. ROT13 is the simplest affine cipher there is. The ROT13 encoder is the closest comparison on this site, and the two answer different questions. Both are free, both run in your browser, and neither asks for an account.
Pick the affine Cipher when you want to see modular arithmetic in action, or you need a cipher with a small, enumerable key space for a classroom exercise. Pick the rot13 encoder when you want the simplest fixed shift, with no key to share or remember.
In practice most people keep both bookmarked. They are small, free, and private, and switching between them costs nothing — paste the same text into each and compare the outputs side by side before deciding which one fits the job in front of you. The habit that saves the most time is deciding the job first and the tool second: once you know whether you need a cipher, a conversion, or a count, the choice between two similar tools is usually obvious.
Common mistakes with a Affine Cipher
Picking a value of a that is not coprime to 26, such as 2, 4, or 13. Those values have no modular inverse, so two different letters can encrypt to the same letter and the message can never be decrypted.
Forgetting that A is 0, not 1. Off-by-one errors are the most common mistake in hand calculations — A=0, B=1, and Z=25, so the alphabet wraps at 26, not 27.
Treating the affine cipher as secure. With only 312 keys, brute force is trivial, and letter frequencies survive encryption, so frequency analysis breaks it quickly. Mixing up encryption and decryption. Decryption uses the inverse of a, not a itself — with a=5, the inverse is 21, and using 5 in both directions gives gibberish. The fix in every case is the same: check the input, check the setting, and test with the worked example before trusting a long result.
If the result still looks wrong after checking the input, run the worked example exactly as written. If the example works and your input does not, the difference is in your input — compare them character by character, including spaces, until the odd one out shows itself.
How to use this Affine Cipher
Type your text, pick a value for a from the list, set b, and choose Encrypt or Decrypt. The result appears live, and the key check above tells you at once whether your value of a can be decrypted. The word counter can help with the next step once you have your output.
Work one letter by hand before trusting a long message — H with a=5, b=8 should give R, and if it does, the rest of the arithmetic is right. Keep a and b written down with the message, or the reader cannot decode it.
The result can be copied with the buttons above it, or shared and printed from the actions on the page. If you use the tool often, bookmark the page — the address never changes, and your last input is not saved, so a fresh visit always starts clean. That also means there is nothing to clear and nothing to log out of when you are done.
Everything on this page is free, with no account and no limit on how often you use it. Your text is processed in your browser and never sent to a server, so drafts, names, and private notes stay on your device. If the result looks wrong, check the input first — a stray space or a missing character is the cause far more often than the tool itself.