RSA Calculator

Interactive walkthrough of RSA public-key encryption and decryption
This tool walks through the mechanics of RSA encryption step by step. It uses small numbers for clarity — no provisions are made for high-precision arithmetic or efficient handling of large values, so keep your choices modest.

Summary of Steps

1
Generate N and r
Pick two primes p and q. N = p×q becomes the modulus; r = (p−1)(q−1) is used to find valid key pairs.
2
Find a factorable K
From the list of candidates equal to 1 mod r, pick one (K) that factors into two usable numbers.
3
Choose e and d
Split K's factors into e and d, both relatively prime to r, so that e×d ≡ 1 (mod r).
4
Encrypt / decrypt
Use e and N to encrypt a numeric message, then d and N to decrypt the ciphertext back to the original.
1

Compute N as the product of two prime numbers p and q

Enter values for p and q, then click to compute N and r.

The values of p and q you provided yield a modulus N, and also a number r = (p−1)(q−1), which is very important. You will need to find two numbers e and d whose product is a number equal to 1 mod r. Below appears a list of some numbers which equal 1 mod r. You will use this list in Step 2.

2

Find a number equal to 1 mod r which can be factored

Enter a candidate value K, then click to factor it.

3

Find two numbers e and d that are relatively prime to N and for which e×d ≡ 1 mod r

Use the factorization info above to split K into two numbers, e and d. Click the button to check correctness.

If your choices of e and d are acceptable, you should see the messages "e*d mod r = 1", "e and r are relatively prime", and "d and r are relatively prime" at the end of this box.

4

Use e and d to encode and decode messages

Enter a message in numeric form. Click the button to encode and decode it. Break your message into small chunks so that the Msg codes are not larger than N. (See the ASCII Reference Table below for ASCII code equivalences.)

Message → Numeric Converter

Type text below to see its ASCII codes. Copy one value at a time into the Msg field — each chunk must be smaller than N.

Bit-Level View (for comparison, not part of RSA math)

RSA itself encrypts using modular exponentiation (Cipher = Msge mod N), not XOR. This panel just shows what a simple XOR cipher would look like using Msg as plaintext and e as the key, so you can see how it differs from RSA.

ASCII Reference Table

Printable characters 32–126 with their decimal codes. Use these values when converting a message character by character, or with the Message → Numeric converter above.

32Space
33!
34"
35#
36$
37%
38&
39'
40(
41)
42*
43+
44,
45-
46.
47/
480
491
502
513
524
535
546
557
568
579
58:
59;
60<
61=
62>
63?
64@
65A
66B
67C
68D
69E
70F
71G
72H
73I
74J
75K
76L
77M
78N
79O
80P
81Q
82R
83S
84T
85U
86V
87W
88X
89Y
90Z
91[
92\
93]
94^
95_
96`
97a
98b
99c
100d
101e
102f
103g
104h
105i
106j
107k
108l
109m
110n
111o
112p
113q
114r
115s
116t
117u
118v
119w
120x
121y
122z
123{
124|
125}
126~