Question: The RSA cryptosystem involves three integers n , e , and d that satisfy certain mathematical properties The public key ( n , e )
The RSA cryptosystem involves three integers n e and d that satisfy certain mathematical properties The public key ne is made public on the Internet, while the private key nd is only known to Bob
If Alice wants to send Bob a message x in n she encrypts it using the function Ex xe mod n where n pq for two distinct large prime numbers p and q chosen at random, and e is a random prime number less than
m p q such that e does not divide m
Example: suppose p and q ; then n and m ; further suppose e ; if Alice wants to send the message x to Bob, she encrypts it as E mod
When Bob receives the encrypted message y he decrypts it using the function Dy yd mod n where d in m is an integer that satisfies the equation ed mod m
Continuing the example above, if d then when Bob receives the encrypted message y from Alice, he decrypts it to recover the original message as D mod
Part II RSA Cryptosystem Problem RSA Library
Implement a library called rsa.py that provides functions needed for developing the RSA cryptosystem and supports the following API
rsa
keygenlo hi generates and returns the publicprivate keys as a tuple ned picking prime numbers p and q needed to generate the keys from the interval lo hi
encryptx n e encrypts x int using the public key n e and returns the encrypted value
decrypty n d decrypts y int using the private key n d and returns the decrypted value
bitLengthn returns the least number of bits needed to represent n
decbinn width returns the binary representation of n expressed in decimal, having the given width and padded with leading zeros
bindecn returns the decimal representation of n expressed in binary
~workspacersa cryptosystem
$ python rsa.py S encryptS
decrypt bitLength
decbin bindec
S
Part II RSA Cryptosystem Problem RSA Library
keygenlo hi
Get a list of primes from the interval lohi
Sample two distinct random primes p and q from that list
Set n and m to pq and p q respectively
Get a list primes from the interval m
Choose a random prime e from the list such that e does not divide m you will need a loop for this Findad in msuchthatedmodmyouwillneedaloopforthis
Return the tuplen e d
encryptx n e
Implement the function Ex xe mod n decrypty n d
Implement the function Dy yd mod n
A tuple is like a list, but is immutable. You create a tuple by enclosing commaseparated values within matched parentheses, eg a If a is a tuple, ai is the ith element in it
Part II RSA Cryptosystem Problem RSA Library
primeslo hi
Create an empty list
Foreachp in lohiifpisaprime,addptothelist Return the list
samplea 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
choicea
Get a random number r in l where l is the number of elements in a Return the element in a at the index r
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
