A mini RSA

The problem

Implement the RSA cipher from scratch with small primes: make a key pair, encrypt and decrypt messages, and show why knowing only the public key is not enough once the primes are large.

Requirements

Technologies

Step by step

  1. Write a prime test and pick two primes p and q, then compute n and phi.
  2. Write the extended Euclidean algorithm and use it to find d.
  3. Encrypt and decrypt a list of numbers and check that the messages return.
  4. Factor n by trial division for small keys and count the steps for primes of growing size.

Expected result

A working toy RSA with a table that shows how the work of breaking the key grows with the size of the primes.

How it is evaluated

Ways to improve it