Question: PYTHON!!!! PLEASE HELP USING PYTHON CODE!!!!!! Revise the substitutionEncrypt function from section 3.5 (p. 102) of the textbook to (1) remove all spaces from the
PYTHON!!!! PLEASE HELP USING PYTHON CODE!!!!!!
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. (CODE IMAGES BELOW)
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 password; (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. Note that substitutionEncrypt and substitutionDecrypt will need to call genKeyFromPass, which calls removeDupes and removeMatches. Starter code for genKeyFromPass, removeDupes, and removeMatches is in the text (p. 106-107); you will need to write a docstring for each function.


3.6 Creating a Key 107 removeMatches (myString, removeString): newStr = "" for ch in myString: def if ch not in removeString: newStr = newStr + ch return newStr Listing 39 Remove the characters in one string from another >>>removeDupes 'topsecret') topsecr >removeMatches ('abcdefghijklmnopqrstuvuxyz', 'topsecr') abdfghijklmnquvwxyz ' >>> removeMatches ('abcdefghijklmnopqrstuvuxyz',removeDupes 'bondjamesbond') 'cfghiklpgrtuvwxyz' Session 3.11 Testing removeDupes and removeMatches Now that we have implemented removeDupes and removeMatches, the rest of our alphabet scrambling algorithm is fairly easy. Listing 3.10 shows the Python code needed to provide a scrambled version of the alphabet using a password as the starting point def genKeyFromPass (password) key = 'abcdefghijklmnopqrstuvwxyz' password = removeDupes(password) lastChar password [-1] last!dx = key, find (1astChar) afterString renoveMatches (key[1astlax+1:) ,password) beforeString - removeMatches (key [: lastIdx],password) key = password + afterString + beforeString return key Listing 3.10 Generating a key starting from a password
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
