RSA is a public-key algorithm for encrypting and signing messages. It uses the receiver's public key to encrypt the data and the receiver's private key to decrypt it.
-
Set:
$e = 65537$ -
Choose two prime numbers
p
andq
so that:$phi(n) = (p-1)(q-1)$ ande
are coprimeNOTE:
phi(n)
ande
are coprime when the greatest common divisor is 1. To calculate that the euclidean algorithm was used -
Calculate:
$n = pq$ -
Calculate:
$ed = 1 (mod (phi(n)))$ NOTE:
d
is calculated using extended euclidean algorithm -
Bundle the keys:
- private key = (
d
,n
) - public key = (
e
,n
)
-
Encryption:
$ciphertext = plaintext ^ e (mod (n))$ -
Decryption:
$plaintext = ciphertext ^ d (mod (n))$
This algorithm is an afficient method for computing the greatest common divisor of two integers - the largest number that divides them both without a remainder.
This algorithm is an extension to the euclidean algorithm. It computes integers x
and y
such that:
The GNU Multiple Precision Arithmetic Library
is a free library for arbitrary precision arithmetic, operating on signed integers, rational numbers, and floating-point numbers. There is no practical limit to the precision except the ones implied by the available memory in the machine GMP runs on.