Aug-14-2021, 08:35 PM
Break the following ciphertext, decrypting one line at a time because each
line has a different key. Remember to escape any quote characters:
qeFIP?eGSeECNNS,
5coOMXXcoPSZIWoQI,
avnl1olyD4l'ylDohww6DhzDjhuDil,
z.GM?.cEQc. 70c.7KcKMKHA9AGFK,
?MFYp2pPJJUpZSIJWpRdpMFY,
ZqH8sl5HtqHTH4s3lyvH5zH5spH4t pHzqHlH3l5K
Zfbi,!tif!xpvme!qspcbcmz!fbu!nfA
my solution:
Is there any way to improve this code so that I can see only deciphered lines? The catch is that each line from the task setting has a different key.
Not sure if my choice of the list is the right way to go...
This is how the solution should look like:
I love my kitty,
My kitty loves me,
Together we're happy as can be,
Though my head has suspicions,
That I keep under my hat,
Of what if I shrank to the size of a rat.
Yeah, she would probably eat me.
line has a different key. Remember to escape any quote characters:
qeFIP?eGSeECNNS,
5coOMXXcoPSZIWoQI,
avnl1olyD4l'ylDohww6DhzDjhuDil,
z.GM?.cEQc. 70c.7KcKMKHA9AGFK,
?MFYp2pPJJUpZSIJWpRdpMFY,
ZqH8sl5HtqHTH4s3lyvH5zH5spH4t pHzqHlH3l5K
Zfbi,!tif!xpvme!qspcbcmz!fbu!nfA
my solution:
thelist = ["qeFIP?eGSeECNNS,", "5coOMXXcoPSZIWoQI,", "avnl1olyD4l'ylDohww6DhzDjhuDil,", "z.GM?.cEQc. 70c.7KcKMKHA9AGFK,", "?MFYp2pPJJUpZSIJWpRdpMFY,", "ZqH8sl5HtqHTH4s3lyvH5zH5spH4t pHzqHlH3l5K", "Zfbi,!tif!xpvme!qspcbcmz!fbu!nfA"] SYMBOLS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890 !?.' for i in thelist: for key in range(len(SYMBOLS)): translated = '' for symbol in i: if symbol in SYMBOLS: symbolIndex = SYMBOLS.find(symbol) translatedIndex = symbolIndex - key if translatedIndex < 0: translatedIndex = translatedIndex + len(SYMBOLS) translated = translated + SYMBOLS[translatedIndex] else: translated = translated + symbol print(f'Key #{key} {translated}')The output is very long so I won't past it but in short, it takes every element in the list, runs all the keys (in the length of SYMBOLS string), prints all, and one of them is the correct key.
Is there any way to improve this code so that I can see only deciphered lines? The catch is that each line from the task setting has a different key.
Not sure if my choice of the list is the right way to go...
This is how the solution should look like:
I love my kitty,
My kitty loves me,
Together we're happy as can be,
Though my head has suspicions,
That I keep under my hat,
Of what if I shrank to the size of a rat.
Yeah, she would probably eat me.