RSA Mathematics Calculator

Compute small educational RSA values: n, phi, public/private exponents, encryption, and decryption. This educational calculator shows the formula, result, and step-by-step interpretation.

Computer ScienceCryptography

Calculator

What this calculator teaches

RSA math is built from modular exponentiation, Euler totients, and modular inverses.

Use the result as a learning aid. For classwork, still show the formula and intermediate reasoning so the final answer is not just a black-box number.

The Mathematics Behind RSA

RSA is a public-key cryptosystem built from modular arithmetic. In the textbook construction, choose two distinct primes p and q, form n=pq, and compute φ(n)=(p−1)(q−1). Choose a public exponent e satisfying gcd(e,φ(n))=1, then find the private exponent d such that ed≡1 (mod φ(n)).

A small integer message m is encrypted as c=mᵉ mod n and decrypted as m=cᵈ mod n. The modular inverse relation between e and d is what makes the round trip work under the assumptions of textbook RSA. Practical systems use much larger primes and standardized padding; raw textbook RSA should not be used directly to protect real data.

StageFormula
Modulusn=pq
Totientφ(n)=(p−1)(q−1)
Key relationed≡1 (mod φ(n))
Encrypt / decryptc=mᵉ mod n; m=cᵈ mod n

For educational inputs, verify that p and q really are prime, that e is coprime to φ(n), and that the message is represented as an integer in the allowed range, typically 0≤m<n. Reusing tiny primes is insecure; the page is designed only to illustrate the number theory.

How to verify a small RSA exercise. First check that p and q are distinct primes. Then compute n and φ(n), confirm gcd(e,φ)=1, and verify that e·d leaves remainder 1 when divided by φ. Finally, encrypt the message and decrypt the ciphertext; the recovered residue should match the original message modulo n.

For hand calculations, repeated squaring is far safer than constructing mᵉ or cᵈ directly. The same fast modular-exponentiation method used elsewhere on CalcNovaHub keeps intermediate numbers small. Remember that this is textbook number theory: real applications additionally need secure key sizes, protected private-key operations, and standardized encoding and padding to resist attacks.

Formula & Symbols

ConceptFormula or rule
Modulusn = pq
Totientφ(n) = (p-1)(q-1)
Private exponentd ≡ e⁻¹ mod φ(n)

Worked example

Example: With p=11, q=13, e=7, the calculator finds d and encrypts a small message.
Example 2: p=5,q=11 gives n=55 and φ=40. With e=3, d=27 because 3·27≡1 (mod 40).
Example 3: For that key, m=7 encrypts to c=13 because 7³ mod 55=13.
Example 4: Decrypting c=13 with d=27 returns 7.
Example 5: If φ(n)=120, e=6 is invalid because gcd(6,120)=6 rather than 1.

Common mistakes

⚠️
Using the wrong input format

Keep lists comma separated, matrices as rows separated by semicolons, and modular inputs as integers.

⚠️
Ignoring assumptions

Some methods require positive probabilities, valid moduli, independent trials, or small educational input sizes.

⚠️
Using composite values for p or q

The textbook φ(n)=(p−1)(q−1) formula assumes p and q are prime.

⚠️
Choosing e without checking coprimality

A modular inverse d exists only when gcd(e,φ(n))=1.

FAQ

Can I use decimals?
Most numerical calculators allow decimals, but modular arithmetic and coding-theory tools usually require integers or binary strings.
Is this for homework checking?
Yes. The page is designed to show both the answer and the reasoning pattern.
Why does the result sometimes say approximate?
Some probability, floating-point, and numerical methods naturally produce approximations.
Why must p and q be prime?
Primality makes φ(pq)=(p−1)(q−1) for distinct p and q and underlies the standard textbook construction.
What does the public key contain?
In textbook RSA the public key is (n,e); the private exponent d is kept secret.
Why is this calculator only educational?
Real RSA requires very large keys, secure prime generation, and padding schemes such as OAEP or PSS. Small textbook examples are not secure.
Can the message number be larger than n?
RSA operates on residue classes modulo n, but textbook examples normally encode the message as an integer from 0 through n−1.

Related calculators

These links will work after the calculators are registered in the final Math layout update.

Formula Explorer connections

Interpretation: This formula uses integer divisibility, modular arithmetic, finite fields or coding relationships. Assumption: Inputs are usually integers with specific modulus or coprimality requirements. Cryptographic examples are educational and not a substitute for vetted security libraries.

Vigenere Index of Coincidence Calculator →Affine Cipher Math Calculator →Caesar Cipher Math Calculator →Math Formula Explorer →