Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using Pyton 3 write a cipher program. In this programming assignment, you will w

ID: 3597150 • Letter: U

Question

Using Pyton 3 write a cipher program.

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:

Cipher Programming Assignment To protect the content of a message, we can hide it by using an algorithm called a cipher https://en.wikipedia.org/wiki/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" c=> d a=> b b=> c If we know the rules of a cipher, we can also go backwards to decrypt d=> c b=> a c=> b 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 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()
elif choice == 3:
break
else:
print(choice, "is not a valid choice")

# copy pastable code link: https://paste.ee/p/ITSUx

'''

Samle run

Welcome to the Secret Message Encoder/Decoder
1. Encode a message
2. Decode a message
3. exit

What would you like to do? 1

Enter a message to encode: hello world
Encoded message: 74@@% <%*@3

Welcome to the Secret Message Encoder/Decoder
1. Encode a message
2. Decode a message
3. exit

What would you like to do? 2

Enter a message to decode: 74@@% <%*@3
Encoded message: hello world

Welcome to the Secret Message Encoder/Decoder
1. Encode a message
2. Decode a message
3. exit

What would you like to do? 3
'''

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote