Problem 1. (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:

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
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.
Transcribed Image 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.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 6 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY