Your Gateway to Cryptographic Mastery
The Affine Cipher is a type of monoalphabetic substitution cipher, which was developed by the French mathematician Étienne Bazeries in the late 19th century. It extends the basic idea of substitution ciphers by incorporating mathematical functions to enhance security. The cipher derives its name from the affine transformation, a type of linear transformation used in mathematics.
The Affine Cipher is based on a mathematical function that combines both a multiplicative and an additive shift to transform each letter in the plaintext. The encryption and decryption processes use modular arithmetic to map letters in a way that the same transformation can be reversed.
gcd(a, 26) = 1
).
Key Definition: Choose keys a
and b
. Ensure that a
is coprime with 26.
Encryption Formula:
E(x) = (a ⋅ x + b) mod 26
where x
is the numerical value of the plaintext letter (A=0, B=1, ..., Z=25).
Example:
a = 5
, b = 8
E(7) = (5 ⋅ 7 + 8) mod 26 = 43 mod 26 = 17
Key Definition: The decryption key a
must have an inverse modulo 26. Compute the modular inverse of a
, denoted as a-1
, such that:
a ⋅ a-1 ≡ 1 mod 26
You can use the Extended Euclidean Algorithm to find a-1
.
Decryption Formula:
D(y) = a-1 ⋅ (y - b) mod 26
where y
is the numerical value of the ciphertext letter.
Example:
a = 5
, b = 8
a-1
. For a = 5
, a-1 = 21
(since 5 ⋅ 21 ≡ 1 mod 26
)D(17) = 21 ⋅ (17 - 8) mod 26 = 21 ⋅ 9 mod 26 = 189 mod 26 = 7