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.
Follow an RSA integer round trip
Choose two small primes and replay the exact modular arithmetic a bit at a time.
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
- 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
| Step | Bit | Prefix | Start | Squared | After bit |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 1 | 1 | 65 |
| 2 | 0 | 2 | 65 | 992 | 992 |
| 3 | 0 | 4 | 992 | 1232 | 1232 |
| 4 | 0 | 8 | 1232 | 1547 | 1547 |
| 5 | 1 | 17 | 1547 | 789 | 2790 |
| Step | Dividend | Divisor | Quotient | Remainder | e coefficient |
|---|---|---|---|---|---|
| 1 | 780 | 17 | 45 | 15 | -45 |
| 2 | 17 | 15 | 1 | 2 | 46 |
| 3 | 15 | 2 | 7 | 1 | -367 |
| 4 | 2 | 1 | 2 | 0 | 780 |
How to use this calculator
- Choose distinct odd primes p and q, a public exponent e, and a message represented as a nonnegative integer below n.
- Read the modulus, Carmichael value, private exponent, and inverse identity. Compare the original, cipher, and recovered integers.
- Switch between encryption and decryption. Move the step slider to examine the exponent bit, its prefix, and each intermediate residue.
- 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
Repeating Decimal Calculator & Remainder Cycle
Convert repeating decimals to reduced fractions or find the shortest decimal period of a fraction. Trace the exact remainders and inspect any digit.
GCF Calculator
Find the greatest common factor (GCF) of two or more integers.
Prime Factorization Calculator
Find the prime factors of any whole number and express it as a product of prime numbers.
