Answer to Question #149158 in HTML/JavaScript Web Application for mohammed

Question #149158
Write a program to decrypt the encrypted Word. The user enters the encrypted word. For example, if you input JCQQA the program should print out HAPPY.
1
Expert's answer
2020-12-06T17:55:28-0500
#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)

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