Calculators.Life Calculator
Math

RSA Key & Ciphertext Calculator

Input Parameters

Scenarios
First prime number factor
Second prime number factor (distinct from p)
Must be coprime to totient and 1 < e < totient
Numeric plaintext value (must be less than n)

Computed Results

Private Key Exponent (d)
2753
Modulus (n = p × q)3233
Totient3120
Encrypted Ciphertext (c)2790
Decrypted Message (m)65
Status & ValidationValid RSA Keypair & Ciphertext Generated.

This RSA calculator determines the modulus, totient, and private key exponent for a given pair of prime numbers and a public exponent. It helps students and cryptography enthusiasts understand the RSA algorithm by encrypting a plaintext message into ciphertext and verifying the decryption process.

Practical Use Cases

The RSA algorithm is a foundational concept in public-key cryptography. This calculator is designed for educational purposes to help users explore the mathematics behind encryption. Common applications include verifying manual cryptography homework, testing the differences between Euler's and Carmichael's totient functions, and understanding how public and private keys are mathematically linked.

Formula & Explanation

The RSA algorithm relies on the mathematical properties of prime numbers and modular arithmetic. The process involves key generation, encryption, and decryption.

1. Key Generation

First, two distinct prime numbers (p and q) are multiplied to find the modulus (n):

n = p × q

Next, the totient is calculated. The calculator supports two methods:

A public exponent (e) is chosen such that it is greater than 1, less than the totient, and coprime to the totient (meaning their greatest common divisor is 1). The private key exponent (d) is then calculated as the modular multiplicative inverse of e modulo the totient:

d × e ≡ 1 (mod Totient)

2. Encryption and Decryption

A numeric plaintext message (m) must be strictly less than the modulus (n). It is encrypted into ciphertext (c) using the public key (n, e):

c = m^e (mod n)

The ciphertext is decrypted back to the original message using the private key (n, d):

m = c^d (mod n)

Verified Scenario Walkthroughs

Here are examples of how the calculator processes different inputs based on the RSA algorithm.

Default Scenario: Standard Euler Totient

If you input Prime Number p as 61, Prime Number q as 53, and use the Euler totient function with a Public Exponent (e) of 17 and a Plaintext Message (m) of 65 (Display Base 10):

Scenario: Small Primes with Carmichael Totient

If you input Prime Number p as 7, Prime Number q as 11, and use the Carmichael totient function with a Public Exponent (e) of 13 and a Plaintext Message (m) of 5 (Display Base 10):

How to Use the Calculator

Follow these steps to generate keys and encrypt a message:

  1. Enter two distinct prime numbers for Prime Number p and Prime Number q.
  2. Select the Totient Function (Euler or Carmichael).
  3. Enter a Public Exponent (e) that is coprime to the calculated totient.
  4. Input a numeric Plaintext Message (m) that is smaller than the modulus (p × q).
  5. Select your preferred Display Base (Base 10, Hexadecimal, Binary, or Octal) to view the results.

Inputs & Outputs

FieldTypeDescription
Prime Number p & qInputTwo distinct prime numbers used as the foundation for the modulus.
Totient FunctionInputThe method used to calculate the totient (Euler or Carmichael).
Public Exponent (e)InputA number coprime to the totient, used for encryption.
Plaintext Message (m)InputThe numeric message to be encrypted. Must be less than the modulus.
Modulus (n)OutputThe product of p and q, used in both public and private keys.
Private Key Exponent (d)OutputThe calculated private key used to decrypt the ciphertext.
Encrypted Ciphertext (c)OutputThe resulting encrypted numeric value.

Frequently Asked Questions

What is the difference between Euler's and Carmichael's totient functions?

Euler's totient function multiplies (p-1) and (q-1), while Carmichael's totient function finds the least common multiple (LCM) of (p-1) and (q-1). Carmichael's function often results in a smaller private key exponent (d) that still correctly decrypts the message.

Why must the public exponent (e) be coprime to the totient?

The public exponent must be coprime to the totient so that it has a modular multiplicative inverse. If they share a common factor greater than 1, the private key exponent (d) cannot be calculated, and decryption will not work.

What happens if the plaintext message (m) is larger than the modulus (n)?

In the RSA algorithm, the message must be strictly less than the modulus. If the message is equal to or larger than the modulus, the modular arithmetic wraps around, and the decrypted message will not match the original input.

Author portrait
About the Author
Arnab Biswas

Calculator developer and SEO strategist who builds practical online calculators and tests calculation logic, input handling, and expected results using real-world scenarios.