The Affine Cipher is a type of substitution cipher that uses mathematical functions for encryption and decryption. It involves two keys, a
and b
, to transform the plaintext.
The encryption function for the affine cipher is given by:
Where:
-
E(x)
is the encrypted character. -
x
is the numerical representation of the plaintext character. -
a
andb
are the keys used for encryption. -
m
is the size of the alphabet (for the English alphabet,).
To decrypt, the following function is used:
Where:
-
is the modular inverse of a
modulom
.
If we choose a = 5
and b = 8
for the English alphabet (where
- To encrypt the letter "C" (which corresponds to
): The result, 18, corresponds to the letter "S", so "C" becomes "S".
The keys
a
andm
must be coprime (i.e.,) to ensure that the encryption can be reversed during decryption.