RSA

RSA is a public key cryptosystem based on the fact that multiplying large primes is easy, while factoring their product is hard.

Key Generation

Choose distinct large primes and , and let

Then

Choose an integer such that

and choose so that

The public key is and the private key is .

Encryption and Decryption

If the plaintext is an integer with , then the ciphertext is

These modular powers are computed efficiently using Binary Exponentiation.

To decrypt, compute

Why Decryption Works

Since , there is some integer such that

If , then Euler’s theorem gives

so

Security

The security idea is that the public key reveals , but recovering or requires factoring into and .