Lab 10: RSA Encryption
In Prelab, we
walked through an example of how RSA encryption works. We will now see how it is implemented
in python.
Preliminaries
- Download RsaWindow.py.
Note that the parts that you need to edit are clearly marked.
- Open RsaWindow.py in JES.
To run, type RsaWindow() in the interaction area.
- Create lab10.txt. At the top of the file, write your name, NetID, resources used, and collaborators.
You should save your responses to the questions here.
RSA Encryption
-
The comments above the function keyGenerate are missing. Please complete them in RsaWindow.py.
# function: keyGenerate
# description:
# input:
# output:
# side effects:
Hint: The input parameter self is a reference to the RsaWindow itself.
Do not worry about the details of this.
-
What is the function crypt used for? (Hint: look at the two locations in the code where the method is called,
the method crypt itself, and lecture notes).
Rotation Encryption
At the top of the page, please note that there are two flags:
- debuggingFlag=1 means that we will print debugging messages to the RsaWindow.
If debuggingFlag=0, there will not be a JTextField on the RsaWindow for the debugging messages.
- rsaFlag=1 means that the encryption scheme used will be RSA.
If rsaFlag=0, there is no encryption scheme used (currently).
For this part of the lab, we will be using the rotation encryption method described in class.
In order to change the encrpytion scheme, please take the following steps:
- At the top of RsaWindow.py, set rsaFlag=0. Click the Load Program button
and try running the program again to verify that no encryption is used
(ie, the message, encrpyted message, and decrpyted message are all the same).
- We will now create the method rotation, which takes in the asciiValue
(a BigInteger between 0 and 65535) and rotates it by the number of characters indicated
by the parameter numRotations. (The encrpyted message can go out of the range 0-65535).
Don't forget to comment your code!
################### Edit This Function for the Rotation Encrpytion part of the lab ###############################
# function: rotation
# description:
# input:
# output:
# side effects:
def rotation(self, asciiValue, numRotations):
pass
Hint 1: We can create a big integer with value k as follows: BigInteger.valueOf(k)
Hint 2: Remember the API from prelab?
-
Change the decrpytit function by removing the line
decryptedAscii = letter
and replacing it with something of the form:
decryptedAscii = self.rotation(value1,value2)
where you must determine what value1 and value2 are.
-
Do the same for the encryptit method.
-
Calling the method self.setDebuggingMessage("debugging string here")
will print your debugging string in the debugging textfield. Use this method to help you
debug the code. Also, leave in at least one call to self.setDebuggingMessage in the rotation
function.
Extra Credit
Create your own encrpytion algorithm (or describe one that was not discussed in class).
- What is the algorithm?
- Walk through an example of encrypting/decrpying a number.
- Is the method you came up with private key or public key?
You do not need to implement the algorithm to get extra credit.
Submitting
Submit the files RsaWindow.py and lab10.txt using assignment
name lab10 in eclipse. Don't forget to include your name, NetID, lab section,
resources used, and collaborators at the
top of allof your files!
Adapted from a lab originally created by Albert Meixner and Tammy Bailey.