Affine Cipher Encoder Decoder Online
Encrypt or decrypt text using affine keys a and b over the alphabet modulo 26.
How to Use the Affine Cipher Tool
Work with multiplicative and additive keys while keeping the same page structure and styling as the rest of Cipher Tools.
Quick Overview
The Affine cipher mixes multiplication and addition over the alphabet modulo 26. It is richer than Caesar but still a classical teaching tool rather than real cryptographic protection.
In practice, that means two keys control the mapping: one multiplies the alphabet index and one shifts it. This page validates the multiplier for you, so bad key choices fail early instead of producing text that cannot be reversed. The math is based on modular arithmetic, which is why only some values of a work.
Key a
Must be coprime with 26 so decoding remains possible.
Key b
Shifts the mapped value after multiplication.
Default Example
This page starts with a=5 and b=8.
Choose Valid Keys
The multiplier key a must be reversible modulo 26, which is why only certain values are allowed. The additive key b can be any value from 0 to 25. That keeps the page within the rules of a reversible substitution cipher.
Apply the Formula
The formula is the useful part of Affine because it shows how the cipher extends a plain shift into a small modular arithmetic system. Once that clicks, the key restrictions become much easier to understand, and you can see how it fits into the larger family of classical ciphers.
E(x) = (ax + b) mod 26Review the Default Example
Example Input
Affine Cipher
Example Output with a=5, b=8
Ihhwvc Swfrcp
This is a good sanity check because it includes uppercase, lowercase, and spacing. If your output looks wrong on short text, the first thing to verify is the selected value of a.
Decode with the Same Keys
To decode, keep the same key pair. If you want a matrix-based next step, continue to Hill Cipher. If you want a simpler shift-based page, go back to Caesar Cipher.
Frequently Asked Questions
Why can't I use every value for a?
Because a must have a modular inverse modulo 26. Without that inverse, decryption is not possible.
Does this tool keep punctuation?
Yes. Only alphabetic letters are transformed.
Is Affine cipher secure?
No. It is still a classical educational cipher rather than strong cryptography.
What does modulo 26 mean here?
It means every calculation wraps around the 26-letter alphabet. Once a value moves past Z, it loops back to A.
Related Tools
ROT13 Encoder / Decoder
Encode and decode text using ROT13 cipher. Rotate letters by 13 positions for simple obfuscation
Caesar Cipher
Encrypt and decrypt text with a configurable Caesar shift from 1 to 25
Atbash Cipher
Encode and decode text using the Atbash mirror alphabet substitution cipher
Vigenere Cipher
Encrypt and decrypt alphabetic text with a keyword-based Vigenere cipher
Morse Code Encoder / Decoder
Convert plain text to Morse code and decode Morse sequences back to readable text
Rail Fence Cipher
Encrypt and decrypt text using the zig-zag rail fence transposition pattern