RSA Encryption Calculator & Modular Exponent Trace

Choose two small odd primes, a public exponent, and an integer message. Check the Carmichael modulus and modular inverse, then replay the encryption and decryption arithmetic one exponent bit at a time.

Classroom modular arithmetic

Follow an RSA integer round trip

The integer round trip reproduced the original message.
Edit the classroom primes and message

Choose distinct odd primes. Use a public exponent coprime to λ(n), and an integer message from zero to n − 1.

Message m
65
Cipher integer c
2790
Recovered message
65
Modulus n
3233
Euler totient φ(n)
3120
Carmichael value λ(n)
780
Private exponent d
413
GCD of m and n
1

17 × 413 = 1 + 9 × 780

Replay square and multiply

Exponent e = 17. Base 65. Each bit squares the residue. Bit 1 also multiplies by the base.

Binary bits 10001

Remainders after each exponent bitStep 1 of 5. Input bit 1. Squared residue 1 and final residue 65, modulo 3233.0%50%100%15Exponent bit stepResidue share of modulus
  • After squaring
  • After bit
  • Selected step

Step 1 of 5 · bit 1 · exponent prefix 1

Start residue
1
After squaring
1
After bit
65
Review arithmetic and export CSV
Encryption bit table
StepBitPrefixStartSquaredAfter bit
1111165
20265992992
30499212321232
408123215471547
511715477892790
Extended Euclidean divisions for e and λ(n)
StepDividendDivisorQuotientRemaindere coefficient
1780174515-45
217151246
315271-367
42120780

How to use this calculator

  1. Choose distinct odd primes p and q, a public exponent e, and a message represented as a nonnegative integer below n.
  2. Read the modulus, Carmichael value, private exponent, and inverse identity. Compare the original, cipher, and recovered integers.
  3. Switch between encryption and decryption. Move the step slider to examine the exponent bit, its prefix, and each intermediate residue.
  4. Open the arithmetic ledger and export both traces and the extended Euclidean divisions in CSV.

The Formula

The mathematical logic powering this calculation is:

For distinct odd primes p and q, n = p × q, φ(n) = (p − 1)(q − 1), and λ(n) = LCM(p − 1, q − 1). Choose 3 ≤ e < n with GCD(e, λ(n)) = 1. The extended Euclidean algorithm finds a coefficient of e that gives remainder 1 modulo λ(n). Reduce that coefficient to the least positive congruent value d. Check e × d = 1 + k × λ(n) for an integer k.

With integer message 0 ≤ m < n, the cipher integer is mᵉ mod n. The recovered message is cᵈ mod n. For each exponent, start with residue 1 and read its binary digits from left to right. Square the residue modulo n for every bit. For a 1 bit, multiply by the base and reduce again modulo n. After each bit the final residue equals the base raised to the exponent prefix, modulo n.

Use classroom odd primes from 3 through 9,973. The calculator validates the chosen primes and uses exact integer arithmetic. Each plotted residue is scaled relative to n so both phases fit the same y-axis. The arithmetic worksheet uses raw integer representatives. For real messages, RFC 8017 defines full schemes such as RSAES-OAEP.

Worked Example

If you input:

  • p: 61
  • q: 53
  • Public exponent e: 17
  • Message integer: 65

Result:

n = 3,233, φ(n) = 3,120, and λ(n) = 780. The least positive inverse d = 413 satisfies 17 × 413 = 1 + 9 × 780. Encryption produces 2,790. Applying d recovers 65.

Frequently Asked Questions

How is the RSA private exponent calculated?

Find the multiplicative inverse of e modulo λ(n) using the extended Euclidean algorithm. The ledger shows each division and the coefficient of e.

Why do some RSA examples give a different private exponent?

This worksheet reduces the inverse modulo λ(n). Textbooks may use φ(n). For 61 and 53 with e = 17, 413 is the least positive inverse modulo 780, and 2,753 is the least positive inverse modulo 3,120. Both are congruent modulo 780.

What happens when the exponent bit is zero?

The step squares the previous residue and reduces it modulo n. A bit of one adds a modular multiplication by the base.

Can a message share a factor with the modulus?

Yes. The integer round trip holds even when GCD(m, n) exceeds 1. With p = 11 and q = 17, message 55 shares factor 11 with n and is recovered exactly.

Similar Calculators