Answer to Question #164676 in Python for Ray

Question #164676

Write the substitutionDecrypt method. Test your algorithm as shown below. Your code should work for any key.

Sample Output:

CipherText: gsv jfrxp yildm ulc

PlainText: the quick brown fox


1
Expert's answer
2021-02-18T14:38:39-0500
import string

all_letters = string.ascii_letters

dict = {}
cipher_txt = str(input("Enter the cipher text: "))
key = int(input("Enter the key: "))
decrypt_txt = []

for i in range(len(all_letters)):
    dict[all_letters[i]] = all_letters[(i - key) % (len(all_letters))]


for char in cipher_txt:
    if char in all_letters:
        temp = dict[char]
        decrypt_txt.append(temp)
    else:
        temp = char
        decrypt_txt.append(temp)

decrypt_txt = "".join(decrypt_txt)
print("Your decrypted plain text is :", decrypt_txt)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS