Link for Project Coded Correspondence:
I managed to get the Caesar cipher working, and have been working to adapt the code for the vigenere cipher.
My code to shift letter index, to the proper index is as follows:
def vigenere_decrypt(message, key):
decrypted_message = “”
key_index = 0
for c in message:
if c in vigenere_alphabet:
# # This needs to find the index of key_index at alphabet, value for index of this one. Original Index +
# index of key ##
decrypted_message += vigenere_alphabet[((vigenere_alphabet.index© + key.index(key_index)) % (len(vigenere_alphabet)))]
## Rotate Key Forward ## key_index =+ 1 if key_index == len(key): key_index = 0 elif c in alphabet: decrypted_message += alphabet[((alphabet.index(c) + key.index(key_index)) % (len(alphabet)))] ## Rotate forward in Key## key_index += 1 if key_index == len(key): key_index = 0 else: decrypted_message += c return decrypted_message
What I am trying to do is to take the character in the message, and add to the empty decrypted_message string the character that has shifted index from, its index of index c and moving it up to the index of my key where it is currently indexed modulo length of alphabet to handle the wrap, if applicable.
There doesn’t seem to be an error with the first library, but my lowercase library “alphabet” appears to be hanging up the code.
When run though i get:
Traceback (most recent call last):
File "*, line 118, in
File "/, line 103, in vigenere_decrypt
decrypted_message += alphabet[((alphabet.index© + key.index(key_index)) % (len(alphabet)))]
TypeError: must be str, not int
I’m trying to figure out why I’m getting getting this error, even though I’m using pretty much the same strategy as I did in the previous exercise, just a more complex way of setting the alphabet.
Thanks in advance for taking a look.