Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

comparing between two lists from the same spot in the list

Blessings,

I have a text file which needs to be decrypted,

It contains the following:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

‘Puackich, hvhnkrally oaths phufhck. All ymr nhhd is Pykemn.’
J.U.U.U Kmltin.
mmps iks nmk eio; —> hkmu

The key to decrypt is this :

if the text holds the value of the following letters in the list >
encrypted = ["a", "b", "d", "m", "f", "g", "r", "y", "i"]

it should be changed to the following >
decrypted = ["m", "y", "c", "a", "t", "i", "s", "b", "g"]

while encrypted[1] == decrypted[1] and so forth

what I tried so far

encrypted = ["a", "b", "d", "m", "f", "g", "r", "y", "i"]
decrypted = ["m", "y", "c", "a", "t", "i", "s", "b", "g"]

new = []
counter = 0
x = len(encrypted)
with open("encrypt.txt") as f:
    lines = f.readlines()
    for i in lines: # will go over words in text
        for b in i: # will go over letters in text
            if b == encrypted[counter]: 
                counter += 1
                new.append[b]
                if counter == x + 1:
                    break
                else:
                    pass
print(new)

>Solution :

This is the approach I’d suggest:

encrypted = "abdmfgryi"
decrypted = "mycatisbg"
lookup = dict(zip(
    encrypted + encrypted.upper(),
    decrypted + decrypted.upper()
))

msg = (
    "'Puackich, hvhnkrally oaths phufhck. All ymr nhhd is Pykemn.' "
    "J.U.U.U Kmltin. mmps iks nmk eio; ---> hkmu"
)

print(''.join(lookup.get(c, c) for c in msg))

The lookup dict is created by zipping the encrypted and decrypted alphabets together into key: value pairs, producing:

{'a': 'm', 'b': 'y', 'd': 'c', 'm': 'a', 'f': 't', 'g': 'i', 'r': 's', 'y': 'b', 'i': 'g', 'A': 'M', 'B': 'Y', 'D': 'C', 'M': 'A', 'F': 'T', 'G': 'I', 'R': 'S', 'Y': 'B', 'I': 'G'}

Given this dict you can easily translate each encrypted letter to its corresponding letter, yielding the output:

'Pumckgch, hvhnksmllb omths phuthck. Mll bas nhhc gs Pbkean.' J.U.U.U Kaltgn. aaps gks nak ego; ---> hkau

which doesn’t look very decrypted to me, but is the "correct" output given your cipher key.

A better cipher key might be:

encrypted = "ehkmortu"
decrypted = "hetomukr"

which yields the output:

'Practice, eventually makes perfect. All you need is Python.' J.R.R.R Tolkin. oops its not him; ---> etor
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading