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
#2
You might want to look at the thread were I posted on hacking(decrypting), the Caesar cypher)here.

If you are trying to get the decryption method to display each letter as it is found then I would think you would need to have it display the frequency of the letter(s) chosen and varied... then displayed.
"Often stumped... But never defeated."
Reply
#3
Hi, thank you for your answer !
I will definitely have a look at the post you mentionned. But I just wanted to ad a little correction : I don't want to have the decryption letter by letter, but word by word, for instance :

key = 0
RTSXNJZW

key = 1
QSRWMIYV
...

key = 5
MONSIEUR

key = 6
LNMRHDTQ

But thank you anywai for your quickness, I do appreciate !
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How can i fix json.decoder.JSONDecodeError ? JgKSuperstar 9 4,639 Oct-30-2021, 11:23 PM
Last Post: JgKSuperstar
  reset on inactivity (building a morse decoder) gerrit1985 7 3,562 Apr-17-2020, 10:22 AM
Last Post: deanhystad
  UTF-8 decoder reports bad byte that is not there Skaperen 0 2,304 Oct-11-2018, 04:46 AM
Last Post: Skaperen
  MP4 decoder jdewk 4 5,595 Jan-13-2018, 10:02 PM
Last Post: jdewk
  JSON Decoder issue Cronax3 2 9,788 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