#storing alphabets in list
li = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
#taking input from user
enc = input("Enter a word: ")
#list for storing occurences of alphabets
cou = []
for i in enc:
cou.append(enc.count(i))
#list for storing keys
key = []
#calculating key values
for i in cou:
if i == 2:
key.append(2//i)
else:
key.append(2*i);
#empty string for storing decrypted string
dec = ""
for i in range(len(enc)):
#finding index of the alphabet in li list
#subtracting that value with key
#and finding the index of decrypted alphabet by mod 26
#then add that character to dec string
dec += li[(li.index(enc[i]) - key[i]) % 26]
#displaying output to the user
print("The Decrypted word is:",dec)
Comments
Leave a comment