Let
Encryption:
Decryption:
with the key:
(Source: Definition 1.4.4, Understanding Cryptography: A Textbook for Students and Practitioners by by Christof Paar and Jan Pelzl)
An affine cipher is a type of substitution cipher defined over a set of
-
Encryption function:
$$y \equiv \alpha x + \beta \mod n$$ -
Decryption function:
$$x \equiv \gamma y + \delta \mod n$$
Where:
-
$x$ is the numerical value of the plaintext character (the index of the character in the alphabet). -
$y$ is the numerical value of the ciphertext character (the index of the character in the alphabet). -
$\alpha$ and$\beta$ are the encryption key coefficients. -
$\gamma$ and$\delta$ are the decryption key coefficients. -
$\gamma$ is the multiplicative inverse of$\alpha$ modulo$n$ , meaning$\alpha \gamma \equiv 1 \mod n$ .
The encryption function is:
Subtract
Multiply both sides by modular inverse of
Rearange and distribute:
We have the decryption function:
Where:
$\gamma = \alpha^{-1}$ $\delta = -\gamma \beta$
Paar, Christof, and Jan Pelzl. Understanding Cryptography: A Textbook for Students and Practitioners. Springer, 2010.
Arizona State University. "Affine Cipher." Accessed October 22, 2024. https://math.asu.edu/sites/default/files/affine.pdf