Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this programming assignment, you will write functions to encrypt and decrypt messages using simple substitution ciphers. Your solution MUST include: a function called encode

In this programming assignment, you will write functions to encrypt and decrypt messages using simple substitution ciphers. Your solution MUST include:

a function called encode that takes two parameters:

key, a 26-character long string that identifies the ciphertext mapping for each letter of the alphabet, in order; plaintext, a string of unspecified length that represents the message to be encoded. encode will return a string representing the ciphertext.

a function called decode that takes two parameters:

key, a 26-character long string that identifies the ciphertext mapping for each letter of the alphabet, in order; ciphertext, a string of unspecified length that represents the message to be decoded.

decode will return a string representing the plaintext.

Copy and paste the following statements into your file as the first two statements of your main program. These lines represent Python lists of messages for you to encode and decode to test the functions you write.

plaintextMessages = [ ["This is the plaintext message.", "bcdefghijklmnopqrstuvwxyza"], ["Let the Wookiee win!", "epqomxuagrdwkhnftjizlcbvys"], ["Baseball is 90% mental. The other half is physical. \t\t- Yogi Berra", "hnftjizlcbvysepqomxuagrdwk"], ["I used to think I was indecisive, but now I'm not too sure.", "mqncdaigyhkxflujzervptobws"], ["Einstein's equation 'e = mc squared' shows that mass and \t\tenergy are interchangeable.", "bludcmhojaifxrkzenpsgqtywv"] ] codedMessages = [ ["Uijt jt uif dpefe nfttbhf.", "bcdefghijklmnopqrstuvwxyza"], ["Qnhxgomhqm gi 10% bnjd eho 90% omwlignh. - Zghe Xmy", "epqomxuagrdwkhnftjizlcbvys"], ["Ulj njxu htgcfj C'gj jgjm mjfjcgjt cx, 'Ep pej jyxj veprx rlhu \t\t uljw'mj tpcez jculjm'. - Mcfvw Zjmghcx", "hnftjizlcbvysepqomxuagrdwk"], ["M 2-wdme uxc yr kylc ua xykd m qxdlcde, qpv wup cul'v gmtd mlw \t\t vuj aue yv. - Hdeew Rdyladxc", "mqncdaigyhkxflujzervptobws"] ]

You may alter the spacing or indentation of the two lines to conform to the rest of your code, but you are not allowed to change the strings or structure of the lists.

plaintextMessages is a list consisting of five items. Each item is a list of two strings corresponding to a plaintext message and a key. For each of these five items, you should:

print the plaintext message.

encode the message and print the ciphertext.

decode the ciphertext message you just calculated and print the plaintext message again. The purpose of this is to demonstrate that your encode and decode functions work properly as inverses of each other.

If you have done this correctly, the output from your program for the first data item should look like the following:

plaintext: This is the plaintext message. encoded: Uijt jt uif qmbjoufyu nfttbhf. re-decoded: This is the plaintext message.

Then print a blank line to separate this block of three lines from the next block.

codedMessages is a list consisting of four items. Each item is a list of two strings corresponding to a ciphertext message and a key. For each of these four items, you should:

print the ciphertext message.

decode the message and print the ciphertext.

If you have done this correctly, the output from your program for the first data item should look like the following:

encoded: Uijt jt uif dpefe nfttbhf. decoded:

Then print a blank line to separate this block of two lines from the next block.

Special notes:

Encrypted and decrypted lower-case letters should map to lower-case letters, as defined by the key.

Encrypted and decrypted upper-case letters should map to upper-case letters. Note that upper-case letters do not appear in the key! (Look at the first character in the expected output shown above: the upper-case "T" maps to an upper-case "U" in the encoded message.) Your program must detect when an upper-case letter appears in the data, and figure out how to convert it to the correct upper-case letter based on the corresponding lower-case letters in the key.

Non-alphabetic characters, such as numbers, spaces, tabs, punctuation, etc. should not be changed by either encode() or decode().

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions