Python Forum
A deciphering problem
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A deciphering problem
#17
Going back to the original question by TS, this is an
attempt to reduce the number of possibilities generated by the "brute force" method.
It assumes plain text, so likely there are spaces between the words.
I believe it will solve all Cesars, generated with this key in any language (that uses these symbols).
I have replaced the symbols not found by '?' and changed the indexing system so i could do try-except.
Next person to do a Cesar should use the alternate symbols list, that I was able to format correctly
with the help of other posters here. Smile
Paul
# import string

thelist = ["qeFIP?eGSeECNNS,", "5coOMXXcoPSZIWoQI,",
           "avnl1olyD4l'ylDohww6DhzDjhuDil,",
           "z.GM?.cEQc. 70c.7KcKMKHA9AGFK,", "?MFYp2pPJJUpZSIJWpRdpMFY,",
           "ZqH8sl5HtqHTH4s3lyvH5zH5spH4t pHzqHlH3l5K",
           "Zfbi,!tif!xpvme!qspcbcmz!fbu!nfA"]

# SYMBOLS = f"{string.ascii_letters}{string.digits}{string.punctuation} " # add space
SYMBOLS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 !?.'

def newindex(letter, shft):
    try:
        idxnew =  SYMBOLS.index(letter) + shft
        if idxnew >= len(SYMBOLS):
            idxnew = idxnew  - len(SYMBOLS) 
        return SYMBOLS[idxnew]
    except:
        return '?'
    
idxspace = SYMBOLS.index(' ')
textline = ''

for line in thelist:
    letterIndex = 0
    IcanReadIt = False
    while not IcanReadIt:
        try:
            shft = idxspace - SYMBOLS.index(line[letterIndex])
            for letter in line:
                textline += newindex(letter, shft)
            print(f'> > > > > > > > > > > > >  {textline}')
            answ = input('Can you read this ? (y/n) ')
            if answ.lower() == 'y':
                IcanReadIt = True
            textline = ''
        except:
            textline += '?'
        letterIndex += 1
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Reply


Messages In This Thread
A deciphering problem - by Truman - Aug-14-2021, 08:35 PM
RE: A deciphering problem - by ibreeden - Aug-15-2021, 07:31 AM
RE: A deciphering problem - by DPaul - Aug-16-2021, 07:19 AM
RE: A deciphering problem - by ibreeden - Aug-16-2021, 05:43 PM
RE: A deciphering problem - by Yoriz - Aug-16-2021, 07:25 PM
RE: A deciphering problem - by Truman - Aug-16-2021, 07:53 PM
RE: A deciphering problem - by Yoriz - Aug-16-2021, 08:02 PM
RE: A deciphering problem - by DPaul - Aug-17-2021, 06:19 AM
RE: A deciphering problem - by jamesaarr - Aug-18-2021, 08:12 AM
RE: A deciphering problem - by ibreeden - Aug-17-2021, 09:08 AM
RE: A deciphering problem - by DPaul - Aug-17-2021, 09:47 AM
RE: A deciphering problem - by ibreeden - Aug-17-2021, 10:22 AM
RE: A deciphering problem - by ibreeden - Aug-18-2021, 02:11 PM
RE: A deciphering problem - by Yoriz - Aug-18-2021, 05:12 PM
RE: A deciphering problem - by DPaul - Aug-19-2021, 02:47 PM
RE: A deciphering problem - by Truman - Aug-21-2021, 03:28 PM
RE: A deciphering problem - by DPaul - Aug-22-2021, 09:16 AM
RE: A deciphering problem - by Yoriz - Aug-22-2021, 11:53 AM
RE: A deciphering problem - by ibreeden - Aug-23-2021, 09:27 AM
RE: A deciphering problem - by DPaul - Aug-23-2021, 04:00 PM
RE: A deciphering problem - by Yoriz - Aug-23-2021, 04:18 PM
RE: A deciphering problem - by ibreeden - Aug-23-2021, 05:03 PM
RE: A deciphering problem - by DPaul - Aug-23-2021, 05:24 PM
RE: A deciphering problem - by Yoriz - Aug-23-2021, 06:05 PM
RE: A deciphering problem - by DPaul - Aug-24-2021, 07:07 AM
RE: A deciphering problem - by ibreeden - Aug-24-2021, 02:58 PM

Forum Jump:

User Panel Messages

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