The Affine Cipher is a type of monoalphabetic substitution cipher, where each letter in an alphabet is mapped to its numeric equivalent, encrypted using a simple mathematical function, and then converted back to a letter. The encryption function for a letter
is given by:
![]()
Here,
is the numeric equivalent of a letter,
and
are the keys of the cipher, and
is the size of the alphabet. For the standard English alphabet,
is 26.
The decryption function is:
![]()
Where
is the encrypted numeric equivalent, and
is the modular multiplicative inverse of
modulo
.
Conditions for the Affine Cipher to Work
The Affine Cipher relies on several conditions to ensure that it functions correctly and securely:
1. Choice of
and
:
– The key
must be chosen such that it is coprime with
. This means that the greatest common divisor (GCD) of
and
must be 1. This condition ensures that
has a modular multiplicative inverse
, which is important for the decryption process.
– The key
can be any integer from 0 to
. This key is used to shift the letters in the alphabet.
2. Modular Arithmetic:
– The operations of addition and multiplication in the encryption and decryption processes are performed modulo
. This ensures that the result stays within the bounds of the alphabet.
3. Alphabet Size (
):
– The size of the alphabet,
, must be known and agreed upon by both the sender and the receiver. For the standard English alphabet,
is 26.
Detailed Explanation with Examples
Encryption Example
Let's consider an example with
,
, and
. We will encrypt the letter 'H'.
1. Convert 'H' to its numeric equivalent:
(since A = 0, B = 1, …, H = 7, …, Z = 25).
2. Apply the encryption function:
![]()
![]()
![]()
![]()
![]()
3. Convert the numeric result back to a letter:
.
Thus, 'H' is encrypted to 'R'.
Decryption Example
To decrypt 'R' back to 'H', we need to find the modular multiplicative inverse of
modulo 26. The inverse
is a number such that:
![]()
Using the Extended Euclidean Algorithm, we find that the modular inverse of 5 modulo 26 is 21. Now, we apply the decryption function:
![]()
![]()
![]()
![]()
![]()
Convert the numeric result back to a letter:
.
Thus, 'R' is decrypted back to 'H'.
Importance of Coprime Condition
The requirement that
and
be coprime is important. If
is not coprime with
, the modular multiplicative inverse
does not exist, and decryption becomes impossible. For example, if
and
, the GCD of 13 and 26 is 13, which is not 1. Therefore, 13 does not have an inverse modulo 26, and the Affine Cipher would fail.
Practical Considerations
1. Key Space:
– The key space of the Affine Cipher is determined by the number of valid pairs
. For the English alphabet, there are 12 possible values for
(since there are 12 numbers less than 26 that are coprime with 26) and 26 possible values for
, resulting in a total key space of
possible keys.
2. Security:
– The Affine Cipher is not secure by modern standards. It is vulnerable to frequency analysis attacks because it is a monoalphabetic substitution cipher. Each letter in the plaintext is always encrypted to the same letter in the ciphertext, preserving the frequency distribution of the letters.
3. Historical Context:
– The Affine Cipher is a classical cipher and was used in the past when computational resources were limited. It provides a simple introduction to the concepts of modular arithmetic and cryptographic transformations.
The Affine Cipher is a straightforward example of a classical substitution cipher that utilizes modular arithmetic. For it to work correctly, the key
must be coprime with the size of the alphabet
, ensuring the existence of the modular multiplicative inverse necessary for decryption. Though not secure by contemporary standards, the Affine Cipher serves as an educational tool for understanding the principles of encryption and decryption in the context of classical cryptography.
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

