The key space of an affine cipher is a fundamental concept in classical cryptography, particularly within the domain of modular arithmetic and historical ciphers. The affine cipher is a type of substitution cipher, which means it replaces each letter in the plaintext with a corresponding letter in the ciphertext according to a mathematical function. Understanding the key space of an affine cipher involves delving into the mathematical structure of the cipher and exploring the parameters that define it.
The affine cipher operates on the principle of affine transformations in modular arithmetic. Specifically, it uses the function:
![]()
where:
–
is the encryption function.
–
represents the numerical value of the plaintext letter.
–
and
are the keys of the cipher.
–
is the size of the alphabet (typically 26 for the English alphabet).
–
denotes the modulus operation, ensuring the result wraps around within the range of the alphabet.
To decrypt the ciphertext, the inverse function is used:
![]()
where:
–
is the decryption function.
–
represents the numerical value of the ciphertext letter.
–
is the modular multiplicative inverse of
modulo
.
The key space of the affine cipher is defined by the set of all possible pairs
that can be used as keys. However, not all pairs of
are valid. For a pair
to be a valid key,
must be coprime with
, meaning that the greatest common divisor (gcd) of
and
must be 1. This requirement ensures that
has a modular multiplicative inverse, which is necessary for the decryption process to work correctly.
To explore the key space in detail, consider the following steps:
1. Determine Valid Values for
:
– The value of
must be coprime with
. For the English alphabet,
. The values of
that are coprime with 26 are those integers less than 26 that do not share any common factors with 26 other than 1.
– The integers that are coprime with 26 are: 1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, and 25. There are 12 such integers.
2. Determine Valid Values for
:
– The value of
can be any integer from 0 to
. For the English alphabet, this means
can range from 0 to 25. There are 26 possible values for
.
3. Calculate the Total Key Space:
– The total number of possible keys is the product of the number of valid values for
and the number of possible values for
.
– Therefore, the total key space is
.
This means there are 312 unique pairs
that can be used as keys in an affine cipher when
.
Examples
To illustrate the affine cipher, consider the following example:
Encryption Example:
Suppose we choose
and
. The encryption function becomes:
![]()
Let's encrypt the plaintext "HELLO". First, we convert each letter to its corresponding numerical value (A = 0, B = 1, …, Z = 25):
– H = 7
– E = 4
– L = 11
– L = 11
– O = 14
Applying the encryption function to each letter:
–
(R)
–
(C)
–
(L)
–
(L)
–
(A)
The ciphertext is "RCLLA".
Decryption Example:
To decrypt the ciphertext "RCLLA" using the same keys
and
, we need the decryption function:
![]()
First, we find the modular multiplicative inverse of
modulo 26. The inverse
is the integer such that:
![]()
Using the extended Euclidean algorithm, we find that
.
Now, the decryption function becomes:
![]()
Applying the decryption function to each letter in the ciphertext:
– R = 17
– C = 2
– L = 11
– L = 11
– A = 0
–
(H)
–
(E)
–
(L)
–
(L)
–
(O)
The decrypted plaintext is "HELLO".
Key Space Analysis
The key space of an affine cipher is relatively small compared to modern cryptographic standards. With only 312 possible keys for the English alphabet, an exhaustive search (brute force attack) is feasible. This limited key space is one of the reasons why the affine cipher is not secure by contemporary standards. However, it serves as an excellent educational tool for understanding the principles of modular arithmetic and the structure of classical ciphers.
Practical Implications
In modern cryptography, the security of a cipher is heavily dependent on the size of its key space. A larger key space makes it more difficult for an attacker to perform a brute force attack. For example, the Advanced Encryption Standard (AES) uses key sizes of 128, 192, or 256 bits, resulting in key spaces of
,
, and
possible keys, respectively. These key spaces are astronomically larger than that of the affine cipher, providing a much higher level of security.
The affine cipher, with its key space of 312 possible keys for the English alphabet, is a simple yet instructive example of classical cryptography. It demonstrates the application of modular arithmetic and the importance of key selection in ensuring the security of a cipher. While it is not suitable for modern cryptographic needs, the affine cipher remains a valuable educational tool for those studying the history and fundamentals of 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

