project1-fa22 September 16, 2022 1 Project 1 1.1 MCS 260 Fall XXXXXXXXXXInstructors Shulman and Stibitz 1.2 Instructions: 1.2.1 Deadline This project must be submitted to Gradescope by 11:59pm CDT on...

Help with encrypting and decrypting codes


project1-fa22 September 16, 2022 1 Project 1 1.1 MCS 260 Fall 2022 - Instructors Shulman and Stibitz 1.2 Instructions: 1.2.1 Deadline This project must be submitted to Gradescope by 11:59pm CDT on Friday 23 September 2022. 1.2.2 Collaboration and academic honesty This project is to be completed individually. You may not consult with any classmates or any- one other than your instructor or TA about the project. The only resources you may use when completing the project are • Materials posted on the course Blackboard page (which come from content discussed in lec- ture) • The course textbook and “further resources” listed in the Syllabus If you are unsure about whether a resource is allowed, then please ask your instructor. You should also consult the course syllabus for a further explanation of academic honesty. 1.2.3 What to do if you’re stuck -Email or chat with your instructor. -Come to office hours. -Talk to your TA. 1.3 What to submit Submit the following to Gradescope: • Two Python files titled project1_functions.py and project1_input.py that perform the actions described below. 2 Project description The goal of this project is to create a program that encrypts and decrypts information. In particular, you are going to write functions that accept strings containing only uppercase letters and the space character ” ” and either encrypt or decrypt that string based on a “key”. The rest of this section describes in more detail the functions you will write. 1 2.1 Encrypting and decrypting To encrypt information (or a message) is to convert that information into another form so when the encrypted information is accessed, the only person who can understand it is the intended person. That intended person then decrypts the information to determine the original information. The original piece of information that is being encrypted is called the plaintext and the encrypted piece of information is called the ciphertext. Here is an example. Assume that Alice wants to send the plaintext message "MCS IS COOL" to Bob, but she wants to encrypt it. One simple encryption scheme would be to shift the letters: A becomes B, B becomes C, C becomes D, …, Z becomes " ", and " " becomes A. [Note that Alice is shifting each letter up one unit in the alphabet, and she is assuming that the space character is the 27th letter of the alphabet.] Then her ciphertext message would be "NDTAJTADPPM". Once Bob receives this message, he can decrypt it by performing the reverse shift. In the previous example, the key was 1 since each letter of the alphabet was shifted up one unit. Once Bob knew that the key was 1, he simply reverse shifted each letter by one unit. The key can be any integer between 0 and 26. Note, however, that if the key were 0, then we aren’t performing any shift and therefore we are not really encrypting the message. Therefore, we are going to assume that the key is some integer between 1 and 26. 2.1.1 Encryption function You are going to write a function encrypt(M,k) which takes two inputs: M should be a string and k should be an integer. If M or k are not a string or integer, respectively, then your function should return the integer 0 and exit the function. The string M should only contain uppercase letters and the space character. If M does not follow this structure, your function should return the integer 1 and then exit. If the string M is good, but if k is not an integer between 1 and 26, then your function should return the integer 2 and then exit. If M and k are proper inputs, then encrypt should return the string of characters where each character has been shifted up by k units as described above. When checking if M contains only uppercase letters and the space character, and when shifting each character, you should be using the ord( ) function. Recall that ord( ) converts each character to its ASCII value, and that ord("A") = 65, ord("Z") = 90, and ord(" ") = 32. 2.1.2 Decryption function The second function you will write will be decrypt(M,k) and also accepts two inputs that have the same conditions as the encrypt function. The inputs M and k should be checked just like they were for the encrypt function. If M and k are proper inputs, then decrypt should return the string of characters where each character is shifted backwards k units. Again, when checking M and k, and when shifting characters, you should be using the ord( ) function. 2 2.1.3 Examples Because the encrypt and decrypt functions are inverses of one another, this means that for any proper message M and any proper integer k, the code encrypt(decrypt(M,k),k) should return M and the code decrypt(encrypt(M,k),k) should return M too. Here are some further examples: 1. encrypt(168,4) and decrypt(20,"ABC") should return 0 2. encrypt("abc def",8) should return 1 3. decrypt("ABC DEF",27) should return 2 4. encrypt("MCS IS COOL",1) should return "NDTAJTADPPM" and decrypt("NDTAJTADPPM",1) should return "MCS IS COOL" 5. encrypt("ABC XYZ",7) should return "HIJGDEF" Both of these functions should be inside the file project1_functions.py. The definitions of these functions should be the only objects in this Python file. 2.1.4 Now the project1_input.py file … When testing this project on your own computer, you want to make sure that project1_functions.py and project1_input.py reside in the same directory. The first line of code in the project1_input.py file should be the line import project1_functions This will ensure you have access to the encrypt and decrypt functions inside the project1_functions.py file (which will be needed). Recall that in order to call from , use the command .. So for example, if you want to use the encrypt function as part of the project1_input.py script, you will type project1_functions.encrypt(M,k). When the project1_input.py file gets executed, it should 1. Prompt the user (using input( )) if they would like to encrypt or decrypt a message. It should look like this: Would you like to encrypt or decrypt a message? Answer by typing either "encrypt" or "decrypt": • If the user did NOT type either encrypt or decrypt exactly, then print the error message You did not type encrypt or decrypt exactly. and then exit the script. • If they did type encrypt or decrypt exactly, then it should 2. Prompt the user for a key: Enter the key for (encryption|decryption). Remember the key should be an integer between 1 and 26: • If the user did NOT type a proper integer, then print the error message 3 That is not a valid key. and then exit the script. • If they did type a valid key, then it should 3. Prompt them to enter their message. It should also remind them of the proper message syntax: Enter the message to (encrypt|decrypt). Remember this message should only contain uppercase letters and the space symbol: • If the message is not proper, then print the error message Your message contains invalid characters. and then exit the script. • If the message is proper, then your function should print the encrypted or decrypted message, and then exit the script. In your second and third prompts, you should not have (encryption|decryption) or (encrypt|decrypt) verbatim, but rather use the words that correspond to the user’s response from the first prompt. 2.2 Grading breakdown 2.2.1 Autograder (86 points) • Check that files project1_functions.py and project1_input.py were submitted - 3 points • Check that functions encrypt and decrypt were defined in project1_functions.py - 3 points • Check that the Python interpreter accepts the files project1_functions.py and project1_input.py as valid Python code - 4 points • Check that encrypt and decrypt return proper errors when M and k are not valid inputs - 16 points total • Functional tests of encrypt and decrypt - 40 points total • Functional tests of conditional statements in project1_input.py file - 20 points total Note: You may submit your documents to Gradescope as often as you like. When you feel you have made some substantive progress and would like to test your code, then resubmit. We will only grade your final submission posted to Gradescope. However, do not only test your code through Gradescope (see the final word below). 2.2.2 Manual review (14 points) We will review your code manually and look for basic coding standards. The two main parts of the manual check will be for commenting your code and providing a docstring for the encrypt and decrypt functions. For commenting, a general rule of thumb is there should be one comment for every four to six lines of code. These comments should describe what you’re doing and/or why you’re doing it. 4 2.2.3 Autograder workarounds If we see that your program does not do what was requested in this document, but the error was not detected in the automated testing, a deduction may be given at this point. The scores assigned by the autograder will not be changed during manual review unless we discover some kind of intentional wrongdoing (such as an attempt to circumvent or reverse-engineer the autograder’s operation). 2.2.4 Final word: It is really important to test locally As you write your project, test it locally on your own computer. Do not try to test it with only the autograder. Make sure your programs run on your own computer before uploading them to Gradescope. It is much harder to debug a broken program based solely on reports you get from the autograder compared to working with your local Python interpreter. 5 Project 1 MCS 260 Fall 2022 - Instructors Shulman and Stibitz Instructions: Deadline Collaboration and academic honesty What to do if you're stuck What to submit Project description Encrypting and decrypting Encryption function Decryption function Examples Now the project1_input.py file … Grading breakdown Autograder (86 points) Manual review (14 points) Autograder workarounds Final word: It is really important to test locally
Sep 22, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here