Question: This is for python. (Question 2, will post others separately.) # 2. Implement gen_key(password) def gen_key(password): Generate a key from a password (as outlined in
This is for python.
(Question 2, will post others separately.)
# 2. Implement gen_key(password) def gen_key(password): """Generate a key from a password (as outlined in chapter 2 of our book): 1. remove duplicates from the password 2. split the alphabet into two parts by using the last letter of the password (with duplicates removed) 3. remove any letters in both parts of the alphabet that appear in the password 4. construct the key by joining the password with the first and second part of the alphabet gen_key('topsecret') # --> 'topsecruvwxyzabdfghijklmnq' :param password: the password used to generate a key :type password: str :return: a string 26 characters long, consisting of all letters from a - z :rtype: str """ # implement this function! (need a hint; check out the book) return '' def sub_encrypt(password, message): """Encrypt a message using the substitution cipher. If a character is not in the key, the character remains unchanged. :param password: the password used to generate a key :type password: str :param message: the message to be encrypted :type message: str :return: the resulting ciphertext as a string :rtype: str """ key = gen_key(password) alpha = gen_consecutive_chars() ciphertext = '' for ch in message: try: ciphertext += key[alpha.index(ch)] except ValueError: ciphertext += ch return ciphertext
I don't understand how to implement this function. (Nor the others I'm going to post.) Can I get a walkthrough on how to do these? (A code + breakdown of why or just comments on it would be awesome.)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
