Question: PYTHON The RivestShamirAdleman system is a simple public key cryptosystem that is based on prime numbers. Heres a very basic outline of how to encrypt

PYTHON

The RivestShamirAdleman system is a simple public key cryptosystem that is based on prime numbers. Heres a very basic outline of how to encrypt using RSA

1. Generate 2 prime numbers p and q. N = p*q. N is the modulus.

2. The Totient Function (N) = (p-1)*(q-1). 3. Choose an integer e such that 1

5. Now, you can encrypt a message by using c = me modulo N

6. You can decrypt the ciphertext, using m = cd modulo N

Specifications

For this homework, you will write a program that involve Python concepts like classes, decorators, generators and iterators. You will be writing an RSA encryption/decryption system that conforms to the following specifications.

Write a class called RSA that will contain all of the functions in the program. In the constructor for RSA initialize an empty list and set variables e and d to 0.

Write a function called inputFunc that reads in the number of entries from the user. Then, read in those many values and add them to the list.

Write a function called printFunc that takes in a number and prints The message is followed by the number.

Write a generator function called primeGen that will take a minimum value as a parameter and then yield the next prime numbers. Please note that this input parameter will be quite large and you might want to use long if youre using Python 2.

Write a function called keyGen. This function will read in a minimum value from the user. Then, it will use the primeGen generator to get the next 2 prime numbers and generate the value N and the keys e and d. Print e and N but not the other values.

You would probably also need to write helper functions for the Lowest Common Multiple (LCM), Greatest Common Divisor (GCD) and the Totient function.

Write a function called encrypt that takes in a number as a parameter and returns the RSA encrypted value of the number.

Write a function called decrypt that takes in an encrypted number as a parameter and returns the RSA decrypted value.

Write a decorator function for printFunc that will print The encrypted before the printed message.

Write another decorator function for printFunc that will print The decrypted before the printed message.

Write a function called messages that calls inputFunc and keyGen and then, uses an iterator to iterate through the list and encrypts each of the numbers using the encrypt function. Store the results in another list. Then, go through the second list and print each encrypted number using the decorator for the encrypted message.

Verify your results be decrypting each of the encrypted messages and checking if you get the old value back. Print the decrypted values using the decorator for the decrypted message.

In main, create an RSA object and call the messages function. Sample Output

This section shows the sample output for the program. Please note that the exceptions raised when the iterator hits the end of the list is not included here, since I checked for the exception while generating the output. Please make sure you do so as well. Also, you might have different values even if you have the same inputs, depending on how e is chosen. As long your decrypted message matched your initial input, you should be fine.

 Enter the number of messages: 5 Enter the messages: 15 97 
201 49 500 Enter the minimum value for the prime numbers: 20304 N is 413105621 
e is 286049 The encrypted message is 106412658 The encrypted message is 367869867 

2

The encrypted message is 393299060 The encrypted message is 70473606 The encrypted message is 409030235 The decrypted message is 15 
The decrypted message is 97 The decrypted message is 201 The decrypted message is 49 The decrypted message is 500 

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 Databases Questions!