This is my assignment: Write a program which DECRYPTS a secret message.
It should first prompt the user for the scrambled alphabet. It then should ask for the secret message. Finally, it outputs the unscrambled version.
Note that there are exactly 26 characters input for the scrambled alphabet. All alphabetic characters are translated into their decoded equivalents (which will take a WHILE loop), and all other, non-alphabetic characters should be output exactly as they were without translation.
This is my code so far:
decrypt = ["*"] * 26
scram_alphabet = input("Please input the scrambled alphabet in order: ")
while len(scram_alphabet) != 26:
scram_alphabet = input("Please input the scrambled alphabet in order. The alphabet must have 26 characters: ")
num = 0
for each_letter in scram_alphabet:
decrypt[num] = ord(each_letter)
num = num + 1
print()
print()
msg = input("Now input your scrambled message: ")
print()
print()
num = 0
alphabet = [" "] * 26
for letter in range (26):
alphabet[letter] = letter + 65
while num < 26:
alphabet [num] = decrypt [num]
print(chr(alphabet[num]))
num = num + 1
for alpha in msg.upper():
if alpha < "A" or alpha > "Z":
print(alpha,end="")
else:
print(chr(decrypt[ ord(alpha) - 65 ]), end="")
I can't seem to figure out how to descramble the alphabet using a while loop.
Currently if I input 'XQHAJDENKLTCBZGUYFWVMIPSOR' as the alphabet and 'VNKW KW BO 1WV WJHFJV BJWWXEJ!' as the secret message, the program prints out the scrambled alphabet and an "unscrambled" message that reads "IZTP TP QG 1PI PLNDLI QLPPSJL!". The unscrambled message is actually "THIS IS MY 1ST SECRET MESSAGE!"
Any helpers?