In the first part of this series, we delved into RSA cryptography, its history, applications, and relevance in today’s world1. As we learned, RSA cryptography is a powerful tool widely used to secure digital communication and information. However, its strength and effectiveness do not come from thin air. Profound mathematical principles and concepts underpin RSA cryptography.
In this second part of the series, our goal is to unravel the mathematics behind RSA cryptography. We aim to explain the fundamental mathematical principles used in RSA, including prime numbers, modular arithmetic, and Euler’s totient function. Further, we will illuminate how these principles are applied in generating RSA keys and the encryption and decryption processes.
We will also shed light on how these mathematical principles contribute to the security of RSA and why despite potential weaknesses, RSA remains a vital tool in securing digital information. We will use formulas and provide examples to illustrate these concepts to assist in understanding.
A prime number is a natural number greater than 1 that has no positive integer divisors other than 1 and itself. For example, the first six prime numbers are and 2. The fundamental role of prime numbers in RSA cryptography cannot be overstated. It is the difficulty in factoring large prime numbers that provides the security backbone of RSA3.
Modular arithmetic, also known as “clock arithmetic”, is a system of arithmetic for integers, where numbers “wrap around” after they reach a certain value, referred to as the modulus4. If we denote the modulus by , the result of a modular operation can be written as:
This means that and leave the same remainder when divided by . In the context of RSA, modular arithmetic allows computations to be managed with large numbers by transforming them into equivalent, smaller numbers3.
Euler’s totient function, often denoted by , is an important mathematical function used in RSA. It is used to determine the number of integers that are relatively prime to a given number, (i.e., numbers that do not share any factor with except 1)5. For a prime number , is simply .
In the context of RSA, where the modulus is the product of two prime numbers and , Euler’s totient function can be calculated using the formula:
This totient function plays a pivotal role in the generation of the RSA public and private keys3.
The process of generating an RSA key pair involves the following steps1:
First, we need to select two distinct prime numbers, and . These primes should be chosen randomly and be of similar bit-length to ensure the security of the key6. The larger these prime numbers are, the more secure the RSA key will be, but it will also make the computations slower.
The modulus is calculated by multiplying the two prime numbers. The modulus is a part of both the public and private keys, and it is used in both the encryption and decryption processes.
Next, Euler’s totient function, , is calculated. As mentioned earlier, for a modulus that is a product of two primes and , Euler’s totient function can be computed using the formula:
The public key exponent, typically denoted by , is a number that should be relatively prime to and . In practice, common choices for are , , or (which is )7.
The private key exponent, typically denoted by , is calculated such that it is the multiplicative inverse of modulo . In other words, we need to find a that satisfies the following condition: