Affine Cipher Simulator
Explore the classical Affine Cipher and experiment with different key values to encrypt and decrypt messages. Visualize how modular arithmetic transforms plaintext into ciphertext with our interactive simulator.
Affine Cipher
Cryptography surrounds us, securing countless aspects of our digital lives, often in ways we take for granted. Have you ever wondered how letters and numbers can be transformed into secret messages? The classical Affine Cipher achieves this using simple yet elegant modular arithmetic. With our interactive simulator, you can explore this encryption method directly. Adjust the keys, encrypt and decrypt messages, and uncover the mathematics behind secure communication. Start your journey into the fascinating world of classical cryptography — experiment with the Affine Cipher today!
Mathematical description
The Affine Cipher is a monoalphabetic substitution cipher that uses a linear transformation to encrypt plaintext letters. Each letter is first converted into a number (A = 0, B = 1, …, Z = 25). The encryption and decryption formulas are:
Encryption:
\( E(x) = (a \cdot x + b) \mod 26 \)
where:
\(x\) = numeric value of the plaintext letter
\(a\), \(b\) = keys (with \(a\) coprime to 26)
Decryption:
\( D(y) = a^{-1} \cdot (y – b) \mod 26 \)
where:
\(y\) = numeric value of the ciphertext letter
\(a^{-1}\) = modular multiplicative inverse of \(a\) modulo 26
Example:
Encrypt plaintext HELLO with keys \(a = 5\), \(b = 8\):
Convert letters to numbers: H=7, E=4, L=11, L=11, O=14
Apply encryption formula:
H → \(E(7) = (5*7 + 8) \mod 26 = 43 \mod 26 = 17\) → R
E → \(E(4) = (5*4 + 8) \mod 26 = 28 \mod 26 = 2\) → C
L → \(E(11) = (5*11 + 8) \mod 26 = 63 \mod 26 = 11\) → L
L → L
O → \(E(14) = (5*14 + 8) \mod 26 = 78 \mod 26 = 0\) → A
Ciphertext: RCLLA
To decrypt RCLLA back to HELLO, use the decryption formula with \(a^{-1} = 21\) (mod 26):
R → \(D(17) = 21*(17-8) \mod 26 = 21*9 \mod 26 = 7\) → H
C → \(D(2) = 21*(2-8) \mod 26 = 21*(-6) \mod 26 = 4\) → E
L → L
L → L
A → \(D(0) = 21*(0-8) \mod 26 = 21*(-8) \mod 26 = 14\) → O
Decrypted text: HELLO