Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
coding a decoder...
#1
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.

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.
Reply


Messages In This Thread
coding a decoder... - by Popkhorn - May-27-2020, 08:19 PM
RE: coding a decoder... - by DT2000 - May-28-2020, 06:43 AM
RE: coding a decoder... - by Popkhorn - May-28-2020, 07:26 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How can i fix json.decoder.JSONDecodeError ? JgKSuperstar 9 4,720 Oct-30-2021, 11:23 PM
Last Post: JgKSuperstar
  reset on inactivity (building a morse decoder) gerrit1985 7 3,590 Apr-17-2020, 10:22 AM
Last Post: deanhystad
  UTF-8 decoder reports bad byte that is not there Skaperen 0 2,320 Oct-11-2018, 04:46 AM
Last Post: Skaperen
  MP4 decoder jdewk 4 5,625 Jan-13-2018, 10:02 PM
Last Post: jdewk
  JSON Decoder issue Cronax3 2 9,807 Sep-13-2017, 09:23 AM
Last Post: Cronax3

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020