Please Help me with this Python 3 programs, thank you so much Cipher Programming
ID: 3597139 • Letter: P
Question
Please Help me with this Python 3 programs, thank you so much
Cipher Programming Assignment To protect the content of a message, we can hide it by using an algorithm called a cipher: Cipher Description A cipher works by replacing the characters in some input. For example, we might swap each "a” with a “b", each "b" with a “c", and each "c" with a "d". That means the word "cab" would be encrypted as "dbc" a=> b If we know the rules of a cipher, we can also go backwards to decrypt b=> a So, "dbc" becomes "cab". Requirements: In this programming assignment, you will write a program called cipher.py that uses a cipher to encode and decode secret messages Cipher Rules Use the following cipher to encode and decode your messages Input Replace with Input Replace with Input Replace with 0 The program should start with a menu. It should ask the user whether they/d like to encode a message, decode a message, or exit. The following section contains sample output.Explanation / Answer
cipher_dict = {
'a': '0',
'b': '1',
'c': '2',
'd': '3',
'e': '4',
'f': '5',
'g': '6',
'h': '7',
'i': '8',
'j': '9',
'k': '!',
'l': '@',
'm': '#',
'n': '$',
'o': '%',
'p': '^',
'q': '&',
'r': '*',
's': '(',
't': ')',
'u': '-',
'v': '+',
'w': '<',
'x': '>',
'y': '?',
'z': '='
}
def getDecoderFromEncoder(encoder_dict):
dec_dict = {}
for key in encoder_dict:
dec_dict[encoder_dict[key]] = key
return dec_dict
decoder_dict = getDecoderFromEncoder(cipher_dict)
def encoder(plaintext):
cipher = ""
for c in plaintext:
if c in cipher_dict:
cipher += cipher_dict[c]
else:
cipher += c
return cipher
def decoder(cipher):
plaintext = ""
for c in cipher:
if c in decoder_dict:
plaintext += decoder_dict[c]
else:
plaintext += c
return plaintext
while True:
print("Welcome to the Secret Message Encoder/Decoder")
print("1. Encode a message")
print("2. Decode a message")
print("3. exit")
print()
choice = int(input("What would you like to do? "))
if choice == 1:
plainText = input("Enter a message to encode: ")
plainText = plainText.rstrip()
print("Encoded message:", encoder(plainText))
print()
elif choice == 2:
cipher = input("Enter a message to decode: ")
print("Encoded message:", decoder(cipher))
print()
else:
break
# copy pastable code link: https://paste.ee/p/URDYl
'''
Samle run
'''