An affine cipher is a type of monoalphabetic substitution cipher that uses mathematical functions to encrypt and decrypt messages. Specifically, the encryption function of an affine cipher uses a linear transformation of the form:
![]()
where:
–
is the numerical equivalent of the plaintext letter.
–
and
are constants that serve as the key to the cipher.
–
is the size of the alphabet (e.g.,
for the English alphabet).
For the affine cipher to be injective, which means each input maps to a unique output (i.e., it is a one-to-one function), the key component
must have a specific property. This property is that
must be coprime with
. Two numbers are coprime if their greatest common divisor (GCD) is 1.
Injectivity and Coprimality
To understand why
must be coprime with
for the affine cipher to be injective, consider the implications of the encryption function:
![]()
If
and
are not coprime, then there exist integers
and
such that:
![]()
This means that
and
share a common factor
. Consequently, there would be multiple values of
that, when multiplied by
and reduced modulo
, could produce the same result. This violates the injectivity requirement because different plaintext letters would map to the same ciphertext letter.
Example of Non-Injectivity
Consider an alphabet of size
and choose
and
. The encryption function becomes:
![]()
Since
,
and
are not coprime. Let's examine the mapping for
and
:
For
:
![]()
For
:
![]()
Both
and
map to the same ciphertext letter, 5, demonstrating non-injectivity.
Ensuring Injectivity
To ensure the affine cipher is injective,
must be chosen such that
. This guarantees that
has a multiplicative inverse modulo
, which is important for decrypting the message. The decryption function is given by:
![]()
where
is the multiplicative inverse of
modulo
. The multiplicative inverse
exists if and only if
.
Example of Injectivity
Consider again an alphabet of size
, but this time choose
and
. The encryption function is:
![]()
Since
,
and
are coprime, ensuring injectivity. Let's examine the mapping for
and
:
For
:
![]()
For
:
![]()
Here,
maps to 3 and
maps to 17, demonstrating that different plaintext letters map to different ciphertext letters, thus maintaining injectivity.
Decryption with Injectivity
Given the encryption function
, we need to find the multiplicative inverse of 7 modulo 26 to decrypt the message. The multiplicative inverse
satisfies:
![]()
Using the Extended Euclidean Algorithm, we find that the multiplicative inverse of 7 modulo 26 is 15 because:
![]()
Thus, the decryption function is:
![]()
Let's decrypt the ciphertext letter 17:
![]()
This shows that the decryption process correctly recovers the original plaintext letter.
An affine cipher can be injective if and only if the constant
used in the encryption function is coprime with the size of the alphabet
. This ensures a one-to-one mapping between plaintext and ciphertext letters, making the cipher both secure and reversible. The injectivity of the affine cipher is important for maintaining the integrity of the encrypted message and ensuring that each plaintext letter maps to a unique ciphertext letter, and vice versa.
Other recent questions and answers regarding EITC/IS/CCF Classical Cryptography Fundamentals:
- Is cryptography considered a part of cryptology and cryptanalysis?
- Will a shift cipher with a key equal to 4 replace the letter d with the letter h in ciphertext?
- Does the ECB mode breaks large input plaintext into subsequent blocks
- Do identical plaintext map to identical cipher text of a letter frequency analysis attact against a substitution cipher
- What is EEA ?
- Are brute force attack always an exhausive key search?
- In RSA cipher, does Alice need Bob’s public key to encrypt a message to Bob?
- Can we use a block cipher to build a hash function or MAC?
- What are initialization vectors?
- How many part does a public and private key has in RSA cipher
View more questions and answers in EITC/IS/CCF Classical Cryptography Fundamentals

