Decrypt: Clear screen Get cipher key (assume user enters integer when prompted f
ID: 3592667 • Letter: D
Question
Decrypt: Clear screen Get cipher key (assume user enters integer when prompted for key request) Check that value entered is between 0 and 127 inclusive Convert cipher key to binary string and strip off "Ob" . *Check for 7-character length (pad beginning with zeros if necessary) . Get message to be encrypted from file Initialize decrypted message string to an empty string Perform XOR operation on each character of cipher key and message . o o o Initialize decrypted_bin_char string to an empty string Slice out each successive 7-bit portion of encrypted message Perform XOR operation and append binary result to decrypted string Convert each binary bit of message character and key to an integer Perform XOR operation on these two bits Convert literal True and False to binary bit & append to output - - Append "Ob" of decrypted _bin_ char and get ASCIl integer value o Convert ASCIl integer value to character o Append character to decrypted message string o Clear screen Print decrypted message to standard output Pause screen clearing . The final option allows the user to exit from the application.Explanation / Answer
plainText = raw_input("What is your plaintext? ") shift = int(raw_input("What is your shift? ")) def caesar(plainText, shift): for ch in plainText: if ch.isalpha(): stayInAlphabet = ord(ch) + shift if stayInAlphabet > ord('z'): stayInAlphabet -= 26 finalLetter = chr(stayInAlphabet) cipherText = "" cipherText += finalLetter print "Your ciphertext is: ", cipherText return cipherText caesar(plainText, shift) def caesar(plainText, shift): cipherText = "" for ch in plainText: if ch.isalpha(): stayInAlphabet = ord(ch) + shift if stayInAlphabet > ord('z'): stayInAlphabet -= 26 finalLetter = chr(stayInAlphabet) cipherText += finalLetter print "Your ciphertext is: ", cipherText return cipherText
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.