Extracted text: Problem 1. (RSA Library) Implement a library called rea.py that provides functions needed for developing the RSA cryp- tosystem. The library must support the following API: rsa generates and returns the public/private keys as a tuple (n, e, d), picking prime numbers p and q needed to generate the keys from the interval [1o, hi) encrypts x (int) using the public key (a, e) and returns the encrypted value decrypts y (int) using the private key (a, d) and returns the decrypted value returns the least number of bits needed to represent a returns the binary representation of a expressed in decimal, having the given width and padded with leading zeros returns the decimal representation of a expressed in binary keygen (lo, hi) евcrypt (x, a, е) decrypt (y, n, d) bitLength (n) dec2bin (n, width) bin2dec (n) > "/vorkspace/project4 $ python3 rsa.py S encrypt (S)- 1743 decrypt (1743) - s bitlength (83) - 7 dec2bin (83) - 1010011 bin2dec (1010011) - 83 Directions: 4 / 7 Project 4 (RSA Cryptosystem) • keygen (1o, hi) Get a list of primes from the interval [lo, hi). Sample two distinct random primes p and q from that list. Set n and m to pq and (p – 1)(g – 1), respectively. Get a list primes from the interval [2, m). Choose a random prime e from the list such that e does not divide m (you will need a loop for this). Find a de [1, m) such that ed mod m = 1 (you will need a loop for this). Return the tuple' (n, e, d). • encrypt (x, n, e) - Implement the function E(x) = x° mod n. . deerypt (y, а, d) Implement the function D(y) = yd mod n. • -prines (lo, hi) Create an empty list. - For each p E [lo, hi), if p is a prime, add p to the list. - Return the list. • sample(a, k) Create a list b that is a copy (not an alias) of a. Shuffle the first k elements of b. Return a list containing the first k elements of b. • choice (a) Get a random number r e [0, 1), where l is the number of elements in a.