Question: ( RSA Library ) Implement a library called rsa.py that provides functions needed for developing the RSA cryp tosystem. The library must support the following

(RSA Library) Implement a library called rsa.py that provides functions needed for developing the RSA cryp tosystem. The library must support the following API: rsa keygen(lo, hi) 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 [lo, hi) encrypt(x, n, e) encrypts x (int) using the public key (n, e) and returns the encrypted value decrypt(y, n, d) bitLength(n) dec2bin(n, width) bin2dec(n) decrypts y (int) using the private key (n, d) and returns the decrypted value returns the least number of bits needed to represent n returns the binary representation of n expressed in decimal, having the given width and padded with leading zeros returns the decimal representation of n expressed in binary keygen(lo, 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 (p1)(q 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 d in [1,m) such that ed mod m =1(you will need a loop for this)- Return the tuple1(n,e,d) encrypt(x, n, e)- Implement the function E(x)= xe mod n decrypt(y, n, d)- Implement the function D(y)= yd mod n

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!