RSA Encryption Calculator


RSA Encryption Calculator



Enter a small prime number. For educational purposes only.



Enter another small, distinct prime number.



Select a public exponent. It must be co-prime to (p-1)*(q-1).



The numeric message to encrypt. Must be less than N (p*q).


What is an RSA Encryption Calculator?

An RSA Encryption Calculator is a tool designed to demonstrate the principles of the RSA algorithm, a cornerstone of modern public key cryptography. It allows users to perform the core operations of RSA: key generation, encryption, and decryption. By inputting two prime numbers and a message, you can see how a public and private key pair is created, how the message is turned into an unreadable ciphertext, and how it is then returned to its original form. This type of calculator is primarily for educational purposes, helping students, developers, and security enthusiasts understand the mathematical foundations of one of the world’s most widely used asymmetric encryption systems.


The RSA Encryption Formula and Explanation

The RSA algorithm involves several distinct steps, from key generation to the final decryption. The security of the entire system relies on the computational difficulty of factoring large prime numbers.

  1. Key Generation:
    • Select two distinct large prime numbers, p and q.
    • Calculate the modulus N = p * q. This N is used for both the public and private keys.
    • Calculate Euler’s Totient Function: phi(N) = (p - 1) * (q - 1). This value is kept secret.
    • Choose a public exponent e such that 1 < e < phi(N) and e is coprime to phi(N) (i.e., their greatest common divisor is 1).
    • Calculate the private exponent d as the modular multiplicative inverse of e modulo phi(N). This means (d * e) % phi(N) = 1.
  2. Encryption: To encrypt a message M (represented as a number where M < N), use the recipient's public key (e, N). The ciphertext C is calculated as: C = M^e mod N.
  3. Decryption: To decrypt the ciphertext C, use the private key (d, N). The original message M is recovered by: M = C^d mod N.
Key Variables in the RSA Algorithm
Variable Meaning Unit Typical Range
p, q Secret prime numbers Unitless Integer Extremely large (e.g., 1024+ bits)
N Modulus Unitless Integer Product of p and q (e.g., 2048+ bits)
phi(N) Euler's Totient Function Unitless Integer Slightly smaller than N
e Public (Encryption) Exponent Unitless Integer Commonly 65537
d Private (Decryption) Exponent Unitless Integer Calculated based on e and phi(N)
M, C Message and Ciphertext Unitless Integer 0 to N-1

Practical Examples of the RSA Encryption Calculator

Example 1: Basic Encryption

  • Inputs:
    • Prime p: 17
    • Prime q: 19
    • Public Exponent e: 5 (A valid choice as it's coprime with (17-1)*(19-1) = 288)
    • Message M: 100
  • Calculation:
    • N = 17 * 19 = 323
    • phi(N) = 16 * 18 = 288
    • Private key d is calculated to be 173 because (5 * 173) % 288 = 1.
    • Encryption: C = 100^5 mod 323 = 225
    • Decryption: M' = 225^173 mod 323 = 100
  • Result: The encrypted ciphertext is 225, which decrypts back to the original message of 100.

Example 2: A Different Message

  • Inputs:
    • Prime p: 7
    • Prime q: 13
    • Public Exponent e: 5
    • Message M: 26
  • Calculation:
    • N = 7 * 13 = 91
    • phi(N) = 6 * 12 = 72
    • Private key d is calculated to be 29 because (5 * 29) % 72 = 1.
    • Encryption: C = 26^5 mod 91 = 64
    • Decryption: M' = 64^29 mod 91 = 26
  • Result: The message 26 is successfully encrypted to 64 and decrypted back. For more information, see our guide on what is asymmetric encryption.

How to Use This RSA Encryption Calculator

This calculator simplifies the RSA algorithm into a few easy steps:

  1. Enter Prime Numbers (p and q): Input two distinct prime numbers. The calculator will validate if they are prime. For the math to be manageable in JavaScript without special libraries, use small primes.
  2. Select Public Exponent (e): Choose a value for 'e' from the dropdown. The calculator will automatically check if it's a valid choice for the primes you entered.
  3. Enter Your Message (M): Input the number you wish to encrypt. This number must be smaller than N (p * q).
  4. Calculate: Click the "Calculate" button. The tool will perform all necessary calculations, including generating N, phi(N), the private key 'd', the encrypted ciphertext 'C', and the decrypted message to verify the process.
  5. Review Results: The calculator will display all intermediate values and the final encrypted and decrypted numbers, providing a clear, step-by-step view of the RSA process.

Key Factors That Affect RSA Encryption

The security and performance of RSA encryption are influenced by several critical factors.

  • Key Size: This is the most crucial factor for security. Key size, measured in bits, refers to the length of the modulus N. A larger key size (e.g., 2048 or 4096 bits) makes it exponentially harder for an attacker to factor N back into p and q, which is the primary attack vector against RSA.
  • Prime Number Selection: The primes p and q must be chosen randomly and should not be too close to each other. Using a robust prime number generator is essential for creating secure keys.
  • Public Exponent (e) Choice: While a small 'e' (like 3 or 17) can make encryption faster, it can be insecure if not implemented with proper padding schemes. A larger, commonly used value like 65537 is often a safe balance of performance and security.
  • Padding Schemes: Real-world RSA implementations never encrypt raw data. They use padding schemes (like OAEP) to format the message before encryption. This prevents several types of cryptographic attacks and ensures the process is not deterministic.
  • Algorithm Implementation: Correctly implementing all steps, especially the modular exponentiation and the extended Euclidean algorithm for finding 'd', is critical. A flawed implementation can introduce vulnerabilities regardless of key size.
  • Private Key Security: The entire security model rests on the private key 'd' remaining absolutely secret. If the private key is compromised, any message encrypted with the corresponding public key can be read. This is vital for secure data transmission.

Frequently Asked Questions (FAQ)

1. Why do I have to use prime numbers?

The security of RSA is based on the difficulty of factoring a large number into its two prime components. If you use non-prime numbers, the resulting modulus 'N' can be factored easily, and the private key can be quickly discovered.

2. What happens if my message number is larger than N?

The RSA algorithm is defined for messages that are integers smaller than N. If the message is larger, it needs to be broken into smaller chunks, with each chunk encrypted separately. This calculator requires M < N.

3. Are the numbers in the calculator secure enough for real use?

No. This is an educational tool and uses numbers small enough for JavaScript to handle without special libraries. Real-world RSA uses keys that are 2048 bits or larger, which corresponds to numbers with over 600 digits.

4. What is a "unitless" value?

In the context of RSA, the inputs and outputs are pure mathematical integers. They don't represent a physical quantity like meters or kilograms, so they are considered unitless.

5. Why is the decrypted message the same as the original?

That is the goal of RSA! The process of encrypting with the public key and then decrypting with the private key is designed to perfectly reverse itself, ensuring the original message is recovered intact.

6. Can I encrypt text instead of numbers?

Yes, but the text must first be converted into a number. Common encoding schemes like ASCII or UTF-8 are used to convert characters into a numeric representation before encryption can occur.

7. What's the difference between public and private keys?

The public key (e, N) is shared with everyone and is used to encrypt data. The private key (d, N) is kept secret by the owner and is the only key that can decrypt that data. This is the core of asymmetric encryption.

8. Is RSA still considered secure?

Yes, when implemented correctly with a sufficiently large key size (2048-bit or more) and proper padding schemes, RSA is a fundamental part of secure communication on the internet, often used in protocols like TLS/SSL and for digital signatures. It is often compared to other methods like the digital signature algorithm.


This RSA Encryption Calculator is for educational purposes only and should not be used for securing sensitive data. Copyright © 2026.



Leave a Reply

Your email address will not be published. Required fields are marked *