''' Caesar's cipher Introduction No doubt you will have seen the ennciphering/deciphering methods with shifting the alphabet. For example, A becomes D, B becomes E, etc. This is something you can do in Python. We start with a message, written in a string. ''' message = 'CAESARSDECIPHERING' ''' Have you ever heared of ASCII (American Standard Code for Information Interchange)? Each character or string has a numerical ASCII value. For A it is 65, for Z it is 95. To convert from ASCII to a string in Python, you use the `chr()` function, whose name originates from the word 'character.' The code below generates a variable `Str`, which holds the alphabet: ''' alphabet = np.arange(65,91) Str = [] for ii in alphabet: Str.append(chr(ii)) Str=''.join(Str) print(Str) ''' In order to decipher our message, we need a variable `Str_decipher`, for which the variable `Str` is shifted. In this case we use a shift (Caesar number) of 2. ''' caesar_num = 2 # Between 0 and 25 Str_decipher = Str[caesar_num:] + Str[:caesar_num] print(Str_decipher) ''' In order to encrypt, we need to: * go over each character in the string * find the location in the regular alphabet (`Str`), with `Str.index(character)` * find the corresponding character in the new alphabet (`Str_decipher`) * append that character to the encrypted message ''' new_message = [] for ii in message: index = Str.index(ii) # Go over each character in the string new_character = Str_decipher[index] # Find the location in the regular alphabet new_message.append(new_character) # Extract the corresponding character in the new alphabet new_message=''.join(new_message) # Stitches all characters in the array to one string print(new_message) ''' Exercise A: Deciphering function You have seen how to encrypt. The challenge is now to decrypt a message. Let's start by making code which takes as input the Caesar number and `message_to_decipher`, and outputs the `message_original`. Name your function `Caesar_decipher`. ''' message = 'EGCUCTUFGEKRJGTKPI' caesar_num = 2 def Caesar_decipher(message,caesar_num): # Your code here ''' Exercise B: Caesar number Can you decipher without the value of the Caesar number given? ''' message_to_decipher = 'KVCQOBFSORKWHVCIHGDOQSG' # Your code here