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
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)
Comments
Leave a comment