RSA Encryption: Unlocking the Power of Prime Numbers

CYber VIaz
3 min readJul 18, 2023

--

Introduction:

In the world of cryptography, secure communication is paramount to protect sensitive information from prying eyes. One of the most popular and powerful encryption algorithms used today is RSA (Rivest-Shamir-Adleman). RSA relies on the mathematical properties of large prime numbers to ensure secure data transmission. In this blog, we will delve into the principles of RSA encryption, explain its core formulae, and provide practical examples to illustrate its effectiveness in safeguarding data.

The RSA Encryption Process:

RSA encryption involves two main steps: key generation and encryption/decryption. Let’s explore each step in detail.

1. Key Generation:

The key generation process lays the foundation for secure communication. It involves generating a pair of keys: the public key (e, n) and the private key (d, n).

a. Choose Two Large Prime Numbers:
The first step is to select two distinct, large prime numbers, p and q. These primes should be kept secret.

b. Calculate the Modulus (n):
The modulus “n” is calculated as the product of the two primes, n = p * q. The value of n is made public and is used as part of both the public and private keys.

c. Compute the Euler’s Totient Function (phi(n)):
The Euler’s totient function “phi(n)” is the number of positive integers less than “n” that are coprime to “n.” For RSA, phi(n) is computed as phi(n) = (p — 1) * (q — 1).

d. Choose the Public Exponent (e):
The public exponent “e” is a small, typically fixed value, and is usually chosen to be 65537 (0x10001) for efficiency and security reasons. “e” must be coprime to phi(n), meaning they should have no common factors other than 1.

e. Compute the Private Exponent (d):
The private exponent “d” is the modular multiplicative inverse of “e” modulo phi(n). In other words, (d * e) mod phi(n) = 1.

2. Encryption and Decryption:

a. Encryption:
To encrypt a message “M,” first convert it into a numerical representation “m.” Then, use the recipient’s public key (e, n) to perform the encryption:
Ciphertext “C” = (m^e) mod n

b. Decryption:
To decrypt the ciphertext “C” back to the original message “M,” use the recipient’s private key (d, n):
Plaintext “m” = (C^d) mod n
Finally, convert the numerical value “m” back to the original message “M.”

Example:

Let’s walk through a simple example of RSA encryption and decryption:

1. Key Generation:
— Choose two prime numbers: p = 11 and q = 17.
— Calculate n = p * q = 11 * 17 = 187.
— Compute phi(n) = (p — 1) * (q — 1) = 10 * 16 = 160.
— Choose public exponent “e” = 7 (since 7 and 160 are coprime).
— Calculate the private exponent “d” as the modular multiplicative inverse of “e” modulo 160. In this case, “d” = 23.

2. Encryption:
— Suppose we want to encrypt the message “HELLO.” Convert it into its numerical representation: M = [H(8), E(5), L(12), L(12), O(15)] = [8, 5, 12, 12, 15].
— Encrypt each number using the recipient’s public key (e = 7, n = 187):
Ciphertext: C = [(8⁷) mod 187, (5⁷) mod 187, (12⁷) mod 187, (12⁷) mod 187, (15⁷) mod 187] = [134, 15, 120, 120, 90].

3. Decryption:
— Decrypt each ciphertext number using the recipient’s private key (d = 23, n = 187):
Plaintext: M = [(134²³) mod 187, (15²³) mod 187, (120²³) mod 187, (120²³) mod 187, (90²³) mod 187] = [8, 5, 12, 12, 15].
— Convert the numerical values back to the original message: “HELLO.”

Conclusion:

RSA encryption is a fundamental pillar of modern cryptography, ensuring secure data transmission and communication. By harnessing the mathematical properties of large prime numbers, RSA provides a robust and efficient method for encrypting and decrypting information. As technology continues to evolve, RSA remains a vital tool in safeguarding sensitive data, bolstering cybersecurity efforts, and shaping the digital landscape of tomorrow. Understanding RSA’s principles and its practical applications empowers us to embrace the power of encryption and secure our digital future.

--

--