Data Source and Methodology
All calculations are based on the Affine cipher mathematical formula as described in cryptographic literature. The alphabet size $m$ is assumed to be 26 (for English). The key $a$ must be coprime with 26 (i.e., $a$ must be 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, or 25).
The Formula Explained
Encoding:
$$ E(x) = (ax + b) \mod m $$Decoding:
$$ D(x) = a^{-1}(x - b) \mod m $$Glossary of Variables
- $x$ Numeric equivalent of the letter (A=0, B=1, ... Z=25).
- $a$ Multiplicative key (must be coprime with m).
- $b$ Additive key (the "shift").
- $m$ Size of the alphabet (usually 26 for English).
- $a^{-1}$ The modular multiplicative inverse of $a$ modulo $m$.
How It Works: A Step-by-Step Example
For example, using keys $a = 5$, $b = 8$, and $m = 26$, to encode the letter 'H' (x=7):
The 17th letter (starting from 0) is 'R'. So, 'H' becomes 'R'.
Frequently Asked Questions (FAQ)
What is an Affine Cipher?
The Affine cipher is a type of monoalphabetic substitution cipher, where each letter in an alphabet is mapped to its numeric equivalent, encrypted using a simple mathematical function, and converted back to a letter.
How does the Affine cipher work?
The Affine cipher encrypts a letter by transforming its position in the alphabet using the formula $E(x) = (ax + b) \mod m$, where $x$ is the letter's position, $a$ and $b$ are keys, and $m$ is the size of the alphabet.
Why must Key A be coprime with 26?
If $a$ is not coprime with 26 (i.e., if it shares a factor, 2 or 13), then the function is not a one-to-one mapping. This means multiple letters would encrypt to the *same* letter, making decryption impossible as information is lost.
Tool developed by Ugo Candido. Content verified by CryptoTools team.
Last reviewed for accuracy on: .