RSA Calculator

This guide is intended to help with understanding the workings of the RSA Public Key Encryption/Decryption scheme. No provisions are made for high precision arithmetic, nor have the algorithms been encoded for efficiency when dealing with large numbers.

JL Popyack, October 1997. Revised July 1999, November 2001, November 2009, June 2010,, December 2010, December 2012


The largest integer your browser can represent exactly is

 

Step 1. Compute N as the product of two prime numbers p and q:

p

q

Enter values for p and q then click this button:

Primality check:


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.

N = p*q

r = (p-1)*(q-1)

Candidates (1 mod r):


Step 2. Find a number equal to 1 mod r which can be factored:

K

Enter a candidate value K in the box, then click this button to factor it:


Prime factors of K:
K factored as the product of two numbers:


Step 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 factor K into two numbers, e and d. Click button to check correctness:

e

d

Consistency check:

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.


Step 4. Use e and d to encode and decode messages:

Enter a message (in plaintext form) here. Click button to encode. It will be converted into numeric form and broken into small chunks so that the "Msg" codes are not larger than N. (See ASCII Code Chart for ASCII code equivalences.)

Message to encode (text):

Msg in numeric form:

Encrypted
Cipher = (Msg)e mod N

To verify that the method works properly, the encrypted message in numeric form (above) is decrypted using the decryption key, d. The decrypted message is shown in numeric form and also is converted to ASCII format. If all goes well, the decrypted message will be the same as the original plaintext message.

Decrypted
Msg = (Cipher)d mod N

 

Decoded message (text):