Last updated: August 19, 2026
RSA Calculator
Creators
Dharmendra SinghReviewers

Creators
Dharmendra SinghReviewers
Quick Answer
This RSA calculator demonstrates textbook RSA with small primes using standard number-theory steps. It computes the modulus n, the totient φ(n), picks a valid public exponent e, and finds the private exponent d as a modular inverse. The tool is intentionally limited to small educational examples and should never be used for production cryptography or secure key generation.
For a small RSA example, multiply the two primes to get n, compute φ of n, choose a public exponent e that is coprime with φ of n, and find d as the modular inverse of e.
Key Takeaways
- RSA starts with two distinct prime numbers p and q.
- The modulus is n = pq and the totient is φ(n) = (p - 1)(q - 1).
- The public exponent e must be coprime with φ(n).
- The private exponent d is the modular inverse of e modulo φ(n).
- This calculator is for educational small-number demonstrations only, not real cryptography.
Creators
Dharmendra SinghReviewers

Creators
Dharmendra SinghReviewers
Formula
n = p × q, φ(n) = (p - 1)(q - 1), choose e with gcd(e, φ(n)) = 1, then d ≡ e^-1 (mod φ(n))
Where:
- p=First prime
- q=Second prime
- n=RSA modulus
- \varphi(n)=Euler totient of n
- e=Public exponent
- d=Private exponent
Worked Examples
Classic textbook primes p = 61 and q = 53
This is the standard small RSA walkthrough used in many introductions to modular arithmetic and public-key cryptography.
- 1Compute n = 61 × 53 = 3233.
- 2Compute φ(n) = 60 × 52 = 3120.
- 3Choose e = 17 because gcd(17, 3120) = 1 and 17 < 3120.
- 4Find d so that 17d ≡ 1 (mod 3120); the modular inverse is d = 2753.
Smaller primes p = 11 and q = 13
Even tiny examples show the same RSA setup process, although they are only useful for learning.
- 1Compute n = 11 × 13 = 143.
- 2Compute φ(n) = 10 × 12 = 120.
- 3Choose e = 17 because gcd(17, 120) = 1.
- 4The modular inverse of 17 modulo 120 is d = 113 because 17 × 113 = 1921 = 1 + 16 × 120.
Primes p = 17 and q = 23
This example produces a slightly larger modulus while still staying in easy hand-check territory.
- 1Compute n = 17 × 23 = 391.
- 2Compute φ(n) = 16 × 22 = 352.
- 3Choose e = 17 because gcd(17, 352) = 1.
- 4Solve 17d ≡ 1 (mod 352) to get d = 145.
Introduction
The RSA Calculator on this page is intentionally small and educational. It takes two distinct prime numbers, forms the modulus n = pq, computes Euler’s totient φ(n) = (p-1)(q-1), chooses a valid public exponent e, and finds the matching private exponent d as a modular inverse. That lets students and curious developers see the full RSA setup with hand-checkable numbers such as 61 and 53. This tool is not for real cryptographic deployment, because it uses ordinary JavaScript numbers and tiny textbook inputs rather than production-strength big integers and security practices.
What this RSA calculator is for
This calculator demonstrates the key-generation math behind RSA using small, safe-to-check integers. It is designed for learning number theory concepts like prime testing, greatest common divisors, Euler’s totient, and modular inverses rather than for creating secure keys.
Use it for homework, demos, and classroom explanations.
Use only small primes that keep all arithmetic easy to verify.
Treat every output as a teaching example, not a secure key.
The calculator automatically picks a valid public exponent when possible.
The core RSA formulas
RSA key setup starts with two primes p and q. Their product is the modulus n. The totient of the modulus is φ(n) = (p - 1)(q - 1). You then choose a public exponent e that is relatively prime to φ(n), and compute d so that ed leaves remainder 1 when divided by φ(n).
Why p and q must be prime and distinct
If p or q is not prime, the totient formula used here is wrong and the key schedule breaks. If p and q are the same prime, the example is also no longer the textbook RSA setup the calculator is meant to illustrate. Distinct primes keep the factorization structure clear and the totient formula valid.
How the public exponent e is chosen
Many real systems prefer 65537 because it is large enough to be conventional while still efficient. Small textbook examples often have φ(n) below 65537, so this calculator tries 65537 first when valid and otherwise falls back to smaller standard choices such as 257, 17, 5, or 3 until it finds one that is coprime with φ(n).
Finding the private exponent d
The private exponent is the modular inverse of e modulo φ(n). In other words, d is the number that makes e × d ≡ 1 (mod φ(n)). The calculator finds this with the extended Euclidean algorithm, which is the standard by-hand and by-code method for modular inverses.
Worked example with 61 and 53
For p = 61 and q = 53, the modulus is 3233 and the totient is 3120. Because 17 shares no common factor with 3120, it works as the public exponent. The modular inverse of 17 modulo 3120 is 2753, so the public key is (3233, 17) and the matching private exponent is 2753.
Where this math appears in practice
The real RSA algorithm powers digital certificates, secure transport layers, key exchange workflows, and digital signatures. Production tools, however, use very large primes, carefully generated randomness, padding standards, and big-integer arithmetic. This page focuses only on the small-number arithmetic skeleton behind those professional systems.
Important limits of this demo calculator
This page uses JavaScript numbers and intentionally small values so students can verify the results manually. That means it is inappropriate for real encryption work. The educational value comes from understanding how n, φ(n), e, and d fit together, not from generating usable keys.
Do not use these outputs for real data security.
Do not use tiny primes outside a learning context.
Do not assume textbook RSA examples include modern padding or protocol safety.
Do use the outputs to practice modular arithmetic and inverse calculations.
Quick Reference Card
RSA quick reference
Quick reference • RSA Calculator
n = pq, φ(n) = (p - 1)(q - 1), choose gcd(e, φ(n)) = 1, then find d with ed ≡ 1 mod φ(n).Valid range: Two distinct small safe integers that are both prime.
Common Values
⚠ Watch Out
- •This tool is not a secure RSA key generator.
- •Inputs must be prime and distinct.
- •Tiny primes are useful only for demonstrations.
- •Textbook RSA examples omit the padding and protocol safeguards required in practice.
Pro Tips
- →Check gcd(e, φ(n)) before trying to find d.
- →Use the prime-number calculator if you are unsure whether an input is prime.
- →Work one full example by hand to understand why the modular inverse matters.
- →Treat the sample ciphertext as a consistency check, not as a security feature.
FAQs
What does this RSA calculator compute?
It computes the RSA modulus n, the totient φ(n), a valid public exponent e, and the matching private exponent d for two small distinct primes.
Why does the calculator insist that p and q are prime?
The totient formula φ(n) = (p - 1)(q - 1) only works directly when n is the product of two primes. Composite inputs break the textbook RSA derivation used here.
Why are small primes used in the examples?
Small primes make the arithmetic easy to inspect by hand. They are appropriate for learning but completely unsuitable for real security.
Why is 65537 not always selected?
65537 only works when it is smaller than φ(n) and coprime with φ(n). In tiny examples, φ(n) is often smaller, so a smaller valid exponent such as 17 is used instead.
How is the private exponent d found?
It is the modular inverse of e modulo φ(n). The calculator finds it with the extended Euclidean algorithm.
Can I use this calculator for real encryption keys?
No. It is an educational demo only. Real RSA requires huge primes, big-integer arithmetic, randomness, secure padding, and careful protocol design.
What is the sample ciphertext output for?
It shows one example encryption using a small demo message so you can connect the key values to an actual modular exponentiation step.