RSA Encryption and Decryption

First Prime Number: p

This is an educational tool for demonstration purposes only. These primes offer encryption of between 7 and 28 bits of data.

In reality, the primes used for RSA encryption are much larger, allowing for the encryption of many more bits of data and producing a primary key that it is almost impossible to decrypt.

Second Prime Number: q

Exponent e

Common exponent values : 3 (21+1), 5 (22+1), 17 (24+1), 257 (28+1), 65537 (216+1). These are Fermat primes.

Enter a modulo value

Totient Function φ(n)


Euler's totient function calculates the number of positive integers less than n that are coprime with n.

Enter a value

Bézout's identity ax + by = 1


Enter a value for a

Enter a value for b

The Theory

Large primes:

p and q

Public Key

n = pq, exponent e

Encrypt x

c = xe mod n

Require d such that

x = xed mod n

Decrypt c

x = cd mod n

Private Key

n = pq, exponent d

Calculation of d:

Totient Function φ(n)

φ(n) = (p - 1)(q - 1)

d is the Modular Inverse of e mod φ(n)

ed = 1 mod φ(n)

⇒ ed = 1 + λφ(n)

⇒ xed = x1 + λφ(n)

 

xφ(n) mod n = 1

⇒ xed mod n = x

ed = 1 + λφ(n)

ed - λφ(n) = 1

Use Bézout's identity to find d

RSA Calculation

First Prime Number: p

Second Prime Number: q

Exponent e

Public Key Pair

Exponent e:

3

Modulus n:

34


Decrypt 9

Value:

Continue with step by step calculation