RSA Key & Ciphertext Calculator
Input Parameters
Computed Results
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):
Next, the totient is calculated. The calculator supports two methods:
- Euler's Totient: Totient = (p − 1) × (q − 1)
- Carmichael's Totient: Totient = lcm(p − 1, q − 1)
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:
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):
The ciphertext is decrypted back to the original message using the private key (n, d):
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):
- Modulus (n): 3233
- Totient: 3120
- Private Key Exponent (d): 2753
- Encrypted Ciphertext (c): 2790
- Decrypted Message (m): 65
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):
- Modulus (n): 77
- Totient: 30
- Private Key Exponent (d): 7
- Encrypted Ciphertext (c): 26
- Decrypted Message (m): 5
How to Use the Calculator
Follow these steps to generate keys and encrypt a message:
- Enter two distinct prime numbers for Prime Number p and Prime Number q.
- Select the Totient Function (Euler or Carmichael).
- Enter a Public Exponent (e) that is coprime to the calculated totient.
- Input a numeric Plaintext Message (m) that is smaller than the modulus (p × q).
- Select your preferred Display Base (Base 10, Hexadecimal, Binary, or Octal) to view the results.
Inputs & Outputs
| Field | Type | Description |
|---|---|---|
| Prime Number p & q | Input | Two distinct prime numbers used as the foundation for the modulus. |
| Totient Function | Input | The method used to calculate the totient (Euler or Carmichael). |
| Public Exponent (e) | Input | A number coprime to the totient, used for encryption. |
| Plaintext Message (m) | Input | The numeric message to be encrypted. Must be less than the modulus. |
| Modulus (n) | Output | The product of p and q, used in both public and private keys. |
| Private Key Exponent (d) | Output | The calculated private key used to decrypt the ciphertext. |
| Encrypted Ciphertext (c) | Output | The 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.