Hello, sorry to bother you, but I'm stuck on a project and I can't figure out what's wrong.
I'm coding a python text decoder (nothing very tedious, this is Caesar code, so a shift in the alphabet, with a key, which indicates how many letters you shift the text by.
I managed to write a code that, for a given text and key, will decrypt the message.
I would now like the program to test all possible keys (numbers between 1 and 25), and display each transcript associated with the key that made it possible to obtain it.
In the idea, my code is functional, but all the combinations are displayed each time, adding one after the other.
Here are the two codes, the functional one allowing to decrypt if you have the key, and the attempt that I can't put in place.
PS: for simplicity's sake, the word to decode is always the same: RTSXNJZW, which means "MONSIEUR" in capital letters, when decoded with a key = 5.
I'm coding a python text decoder (nothing very tedious, this is Caesar code, so a shift in the alphabet, with a key, which indicates how many letters you shift the text by.
I managed to write a code that, for a given text and key, will decrypt the message.
I would now like the program to test all possible keys (numbers between 1 and 25), and display each transcript associated with the key that made it possible to obtain it.
In the idea, my code is functional, but all the combinations are displayed each time, adding one after the other.
Here are the two codes, the functional one allowing to decrypt if you have the key, and the attempt that I can't put in place.
list = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'] for x in range(len(list)): #double the list list.append(list[x]) message = 'RTSXNJZW' key = int(5) def dechiffragedecoding_letter(letter,list,key): for i in range(len(list)): if letter==' ': #in case there is a space return ' ' elif list[i]==letter: return str(list[i-key]) message_decoded = str() for letter in message: message_decoded += decoding_letter(letter,list,key) print(message_decoded)
list = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'] for x in range(len(list)): #double the list liste.append(list[x]) message = 'RTSXNJZW' def decoding_letter(letter,list,key): for i in range(len(list)): if letter==' ': return ' ' elif list[i]==letter: return str(list[i-key]) message_decoded = str() key = 0 for n in range(25): key = key + 1 for letter in message: message_decoded += decoding_letter(letter,list,key) print(key) print(message_decoded)Thank you in advance for your help !
PS: for simplicity's sake, the word to decode is always the same: RTSXNJZW, which means "MONSIEUR" in capital letters, when decoded with a key = 5.