The Affine Cipher is a type of monoalphabetic substitution cipher that uses a simple mathematical function to encrypt and decrypt messages. Here’s a detailed breakdown:
Each letter in the plaintext is first converted into a number. For the English alphabet, a common assignment is A = 0, B = 1, C = 2, ..., Z = 25.
The cipher uses a linear function to transform each number. The general encryption formula is:
E(x) = (a * x + b) mod m
To reverse the encryption, you use the inverse of the multiplicative key (denoted as a⁻¹, which exists because a and m are coprime). The decryption formula is:
D(y) = a⁻¹ * (y - b) mod m
Suppose we choose:
Encryption:
For a plaintext letter represented by x, the ciphertext is calculated as:
E(x) = (5x + 8) mod 26
For example, if x = 2 (which corresponds to the letter C):
E(2) = (5 × 2 + 8) mod 26 = (10 + 8) mod 26 = 18 mod 26
This corresponds to the letter S (if A = 0, then S = 18).
Decryption:
To decrypt, first find the modular inverse of 5 modulo 26. The inverse, a⁻¹, is the number such that (5 × a⁻¹) mod 26 = 1. In this case, a⁻¹ = 21 because (5 × 21 = 105, and 105 mod 26 = 1).
Then, for a ciphertext letter represented by y:
D(y) = 21 * (y - 8) mod 26
If y = 18 (for the letter S):
D(18) = 21 * (18 - 8) mod 26 = 21 * 10 mod 26 = 210 mod 26 = 2
This brings us back to the plaintext letter C.
In summary, the Affine Cipher is an elegant, though historically basic, encryption method that illustrates key concepts in modular arithmetic and cryptography, but it lacks the security needed for modern communications.