Question
using python 3 . Revise the substitutionEncrypt function from section 3.5 (p. 102) of the textbook to (1) remove all spaces from the plaintext message
using python 3 . Revise the substitutionEncrypt function from section 3.5 (p. 102) of the textbook to (1) remove all spaces from the plaintext message before it is encrypted and (2) generate the substitution cipher key from a password. (substitutionEncrypt will call genKeyFromPass to do this.) The password should be a parameter, psw, which will replace key as a parameter in the function header.
Write function substitutionDecrypt, which will have two parameters, cipherText, a string, a message encrypted by substitutionEncrypt, and psw, the password used to generate the encryption key, also a string. substitutionDecrypt should return the original plaintext message with spaces removed (a string).
Finally, write a top-level function, main. main should (a) use Pythons built-in input function to get a string to encrypt and a password; (b) call substitutionEncrypt to encrypt the input string; (c) print the value returned by substitutionEncrypt; (d) call substitutionDecrypt to convert the value returned by substitutionEncrypt back to plaintext; (e) print the value returned by substitutionDecrypt.
Use doctest.testmod to check the simple examples included in the function docstrings. The functions should also return correct values for the test cases given here: subEncrypt('the quick brown fox', 'ajax') 'qdznrexgjoltkblu' subDecrypt('qdznrexgjoltkblu', 'ajax') 'thequickbrownfox' Finally, include code in your .py file to call the main function, to check results for additional strings and passwords.
given codes:
defSubstitutionEncrypt(plainText, key): alphabet = "abcdefghijklmnopqrstuvwxyz " plainText = plainText.lower() cipherText = " " for ch in plainText: idx = alphabet.find(ch) cipherText = cipherText + key[idx] return cipherText def removeDupes(myString): newStr = " " for ch in myString: if ch not in newStr: newStr = newStr + ch return newStr def removeMatches(myString, removeString): newStr = " " for ch in myString: if ch not in removeString: newStr = newStr + ch return newStr def genKeyFromPass(password): key = 'abcdefghijklmnopqrstuvwxyz' password = removeDupes(password) lastChar = password[-1] lastIdx = key.find(lastChar) afterString = removeMatches(key[lastIdx+1:], password) beforeString = removeMatches(key[:lastIdx], password) key = password + afterString + beforeString return key
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started