Question: ) encryptCaesarCipher(plainText, key) - return cipherText. Write a function to perform encryption using the Caesar cipher. The first few lines of this function need to

) encryptCaesarCipher(plainText, key) - return cipherText. Write a function to perform encryption using the Caesar cipher. The first few lines of this function need to create your alphabet using the helper function createAlphabet() you created earlier.

) encryptCaesarCipher(plainText, key) - return cipherText. Write a function to perform encryption

You will have to use a for loop to go through the characters of your plaintext and for each character you will have to choose the character from the alphabet that is key positions forward in the alphabet. Be very careful for the cases where you will have to cycle around the ends of the alphabet. (Hint: You can use your getCharacterForward(char, key) from the previous lab.)

using the Caesar cipher. The first few lines of this function need

If the key is negative, you will have to choose the character from the alphabet that is key positions backward in the alphabet. Be very careful for the cases where you will have to cycle around the ends of the alphabet. (Hint: You can use your getCharacterBackward(char, key) from the previous lab.)

to create your alphabet using the helper function createAlphabet() you created earlier.

Do not hard-code any values in your code, use functions instead - we will be testing your code with the alphabets of different lengths.

import string def createAlphabet(): createAlphabet returns a string that includes all lowercase letters, followed by all upper-case letters, then a space, a comma, a period, a hyphen('-'), a tilde('~'), and a pound symbol ('#'). NOTE: the order of characters in the alphabet is very important! In other words, the string being returned will be 'abcdef...XYZABCDEF...XYZ ,.-~#' (the ellipses ... hide the alphabet letters) lc = string.ascii_lowercase uc = string.ascii_uppercase return lc + uc + " ,.-~#" def getCharacterForward(char, key): Given a character char, and an integer key, the function shifts char forward `key` steps. Return the new character. If 'char' is not a single character, return "None. If 'key' is not an integer, return -1. if len(char) != 1: return None if type (key) != int: return -1 whole_chars = createAlphabet() char_index = -1 for i in range(0, len(whole_chars)): if whole_chars[i] == char: char_index = i if char_index != -1: index_final_char = (char_index + key + len(whole_chars)) % len(whole_chars) return whole_chars[index_final_char] def getCharacterBackward(char, key): Given a character char, and an integer key, the function shifts char backward `key steps. Return the new character. If 'char' is not a single character, return "None. If 'key' is not an integer, return -1. if len(char) != 1: return None if type(key) != int: return -1 whole_chars = createAlphabet() for i in range(0, len(createAlphabet())): if whole_chars[i] == char: return whole_chars[(i-key) % len(whole_chars)] import string def createAlphabet(): createAlphabet returns a string that includes all lowercase letters, followed by all upper-case letters, then a space, a comma, a period, a hyphen('-'), a tilde('~'), and a pound symbol ('#'). NOTE: the order of characters in the alphabet is very important! In other words, the string being returned will be 'abcdef...XYZABCDEF...XYZ ,.-~#' (the ellipses ... hide the alphabet letters) lc = string.ascii_lowercase uc = string.ascii_uppercase return lc + uc + " ,.-~#" def getCharacterForward(char, key): Given a character char, and an integer key, the function shifts char forward `key` steps. Return the new character. If 'char' is not a single character, return "None. If 'key' is not an integer, return -1. if len(char) != 1: return None if type (key) != int: return -1 whole_chars = createAlphabet() char_index = -1 for i in range(0, len(whole_chars)): if whole_chars[i] == char: char_index = i if char_index != -1: index_final_char = (char_index + key + len(whole_chars)) % len(whole_chars) return whole_chars[index_final_char] def getCharacterBackward(char, key): Given a character char, and an integer key, the function shifts char backward `key steps. Return the new character. If 'char' is not a single character, return "None. If 'key' is not an integer, return -1. if len(char) != 1: return None if type(key) != int: return -1 whole_chars = createAlphabet() for i in range(0, len(createAlphabet())): if whole_chars[i] == char: return whole_chars[(i-key) % len(whole_chars)]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!