Do My Homework / Homework Answers / Computer Science homework help / Comp Sci: Python Caesar Cipher Script
Comp Sci: Python Caesar Cipher Script
here is the full assignment description: Project 1 Assignment Overview The Caesar cipher is named after Julius Caesar who used this type of encryption to keep his military communications secret. A Caesar cipher replaces each plaintext letter with one that is a fixed number of places down (or up) the alphabet. The plain-text is your original message; the ciphertext is the encrypted message. The example shown below is a shift of three so that "B" in the plain-text becomes "E" in the ciphertext, a "C" becomes "F", and so on. The mapping wraps around so that "X" maps to "A" and so on. The result of using a shift value of 3 in a Caesar cipher. With this shift value; the letter A maps to D, B maps to E, etc. A Caesar cipher with a shift of 3 Here is the complete mapping for a shift of three: Plain: ABCDEFGHIJKLMNOPQRSTUVWXYZ Cipher: DEFGHIJKLMNOPQRSTUVWXYZABC To encrypt a message simply substitute the plain-text letters with the corresponding ciphertext letter. For example, here is an encryption of âthe quick brown fox jumps over the lazy dogâ using our shift-three cipher (case is ignored): Plaintext: the quick brown fox jumps over the lazy dog Ciphertext: WKH TXLFN EURZQ IRA MXPSV RYHU WKH ODCB GRJ To decrypt the message simply reverse the process. The encryption can also be represented using modular arithmetic after first transforming the letters into numbers according to the scheme: A = 0, B = 1, etc. (which is the index of the alphabet if it is in a string or a list). A shift-three cipher will take the number of each letter (plain_text_char), add 3 (the shift), and then find the remainder after dividing by 26 to get the ciphertext: cipher_text_char = (plain_text_char + 3) % 26. Program Specifications Your task is to write a program that can encrypt and decrypt messages using a Caesar cipher. Additionally, you will also write code that can crack a Caesar cipher. Stated another way, you need to find the shift for the cipher. Once you determine the shift, you know the mapping so you can decrypt the message. When run your program will Present a menu to the user asking them which of three operations they wish to perform: encode a message, decode a message, or crack ciphertext Ask the user if the input is to come from the keyboard or from a file If the input is to come from a file ask the user for the filename to read from and read in the input Otherwise, read the input from the keyboard If the user chose to crack a ciphertext, go to step 8 Prompt for the shift value Perform the requested encoding/decoding Display the result to the screen Go to step 13 Find the most common character in the ciphertext (see Notes on Caesar Cipher Cracking below) Find the shift from "E" to this character in the ciphertext Use the shift to decode each character of the ciphertext and display the resulting plaintext on screen Ask the user if the displayed plaintext appears to be correct; i.e., is it readable in English If the user responds in the negative find the next most common character in the ciphertext go to step 9 Ask the user if they want the output written to a file If the user responds in the positive, prompt for a filename to write to Write the results to the provided file Exit the program Notes on Caesar Cipher Cracking To find the shift you need to know about cracking Caesar ciphers using a technique that has been around for a thousand years. Any language such as English has a known distribution for each letter. For example, the letter "E" is the most common letter in English making up 12.702% of the letters on average (ignoring case). The letter "T" is next (9.056%), followed by "A" (8.17%), and so on (for all see Wikipedia). The order "E"-"T"-"A"-... is what matters for decryption, not the percentage. Note that this ordering might not apply if the text is short. The procedure begins by finding the most common letter. You can guess (and code) that the most common letter maps to "E". You can now find the "shift" from the most common letter in the ciphertext to the expected most common letter "E". For example, if the most common letter in the ciphertext is "H", you know that the shift from "E" to "H" is 3. What about spaces between words and punctuation? In real world ciphertext, there are no spaces or punctuation because those are useful clues for deciphering. Similarly, case can provide clues so ciphertext is generally written all in the same case. In the sample ciphertext provided with this project I have left in punctuation, spaces, and case because they will be helpful for you to recognize that your deciphering is correct or not. You will need to ignore spaces and punctuation when counting letters in the ciphertext (if you forget to ignore them, beware that the space will be the most common character). Your program must also meet the following specifications: You must have and use at least these functions in your program (more are fine and will make testing easier for you). def encode(plaintext: str, shift: int): â str Takes in plaintext (a string) and shift (an integer) and returns the shifted encoding of plaintext as a string. shift must be an integer but can be positive or negative and may be greater that Â±26. Your function must account for this. def decode(ciphertext: str, shift: int) â str Takes in ciphertext (a string) and shift (an integer) and returns the shifted decoding of ciphertext as a string. shift must be an integer but can be positive or negative and may be greater that Â±26. Your function must account for this. def get_shift(text: str, ignore:string) â int, char Takes in text (a string) and ignore (a string) and returns the shift (i.e., the decode key) for string s, and the most common character (if more than one are equally common, return the first letter that occurs in the alphabet). If the text is long enough, we expect the most common character to be "E" so shift would be the shift to get "E" (hint: what is the difference between the position of the most common character and the position of E in the alphabet). For example, if the most common character in the ciphertext is "H", the shift will be -3, the number of characters to get to "E". In that case you would return -3 and "H". The ignore parameter is the string of ciphertext letters to ignoreâthey have been tried but didn't result in readable English text. The ignore parameter allows you to find the next-most-common character by ignoring more common characters. def crack(ciphertext: str) â str Takes in ciphertext (a string) and returns a string. The function cracks the provided ciphertext using brute force as described in the algorithm above. def read_file(filename: str): â str Takes in filename (a string) and returns a string containing the file's text. Any errors related to reading the file should be handled inside the function. def write_file(filename: str, text: str): â None Takes in filename (a string) and text (a string) and returns nothing. The function writes text to a file named filename in the current directory. Any errors related to reading the file should be handled inside the function. def main() The main function calls all the other functions in your program. Having main allows for more easily create a set of test programs to test the other functions because we need to comment out main for those tests. You can test functions separatelyâthat can be a huge advantage in developing correct code faster! If you cannot figure out how to do that, ask the class tutor for guidance. You must validate input. If the user is to enter a number, you must check that what was entered was indeed a numeric value and, if not, loop back prompting the user to give appropriate input. When you do so, be sure to explain to the user what appropriate input is. As Hanlon's razor teaches us, "never attribute to malice that which is adequately explained by stupidity." However, do not insult the user. Be professional in all your prompts. Catch any exceptions that may arise and handle them as best you can. This means re-prompting the user for new input or, at the very least, explaining what when wrong in language they can understand and exiting the program in an orderly fashion. Users should never see a raw Traceback. Likely exceptions that may arise include, but are not limited to, the following: FileNotFoundError FileExistsError KeyboardInterrupt Items 1â9 of the Coding Standard will be enforced for this projectânote the change to include more items. You must include a __name__ == "__main__" line to ensure that the code in your module is is run only if the user invokes it directly. One way to decrypt is to use the two built-in functions that are inverses of each other: ord() and chr(). These work because our letters are based on the ASCII subset of Unicode. However, you are forbidden to use ord() and chr() in this assignmentâit is poor coding to be dependent on ASCII. Using those functions will result in a zero for the assignment. You may not use advanced data structures such as lists, dictionaries, sets, or classes in solving this problem. As this is your first program with functions, do not forget function headers! Extra Credit For 4 points of extra credit protect the user against accidental overwrites of an existing file. This will involve writing to the file in a mode other than "w". Save your completed program in a file named caesar.py.
Get Help With a similar task to - Comp Sci: Python Caesar Cipher Script
Similar orders to Comp Sci: Python Caesar Cipher Script
Send an email, with the current weather information from the target zip code with the weather information.
Create a web form to capture an email address and zip code along with a submit button Create a code behind to consume API from weatherapi.com Send an email, captured from the âemail toâ textbox, with the current weather information from the t...
JAVA project/paper/UML diagram
Java code (150 lines) paper(500 words) UML diagram In addition to the correctness of your code, part of your grade will be based on how organized your code is â how easy is it to read and understand. Proper spacing will aid you in this regard....
Project for CS1302 using JavaFX
THE DEADLINE IS TODAY(4/21) AT 11:00!! It's not updating for some reason. I have done some of this project but it's not working and I need someone to complete it. There is a project description file, as well as my current java files. According to the desc...
unity programming assignment help
Look at pdf, I can't explain well Aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
Tutlance Experts offer help in a wide range of topics. Here are some of our top services:
- Math homework help
- Nursing homework help
- Statistics homework help
- Nursing coursework help
- Capstone project writing services
- Essay writers for hire
- Case study writing help
- Buy college papers online
- Buy college research papers
- College homework help
- Professional resume writing services
- Programming homework help
- Coursework writing help
- Term paper writing help
- Biology homework help
- Do my physics homework
- Dissertation data analysis help
- PhD Dissertation writing services
- Chemistry homework help
Post your project now for free and watch professional experts outbid each other in just a few minutes.