Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 2: Find the Hidden Message (40 pts) Write a program to determine if a simple substitution code is reversible for a given string. The

image text in transcribed
Part 2: Find the Hidden Message (40 pts) Write a program to determine if a simple substitution code is reversible for a given string. The program should ask the ser for a sentenee using input. The program should then enerypt the string into a cipher, decode the cipher, and compare the reult of the decode opcration to the original sentence. If the decoded cipber natches the original, thea the operation is reversibile on the string. Otherwise, it is not reversille Along the way, the program should print out the cipher, the diTereace in kngth between the cipber and the original sentence, the decoded cipher, and a brief message saying whether the operation was reversible. Note that the difference in length shoald always be printed as a positive number Two cxamples of the program run (how it will look when you run it using Wing IDE 101) are provided in files hvr2.part2.output.01.txt and hw2-Part2.0utput.2.txt. (Can be found iside the hu02 files.zip file.) The encryption rules are based on a set of string replacements, they should be applind in this onder exactly: .X4%" replace any a after aspace with 14% replace all occurrences of string he with 7 .a. "> replace aay remmaining e with 90 9 y' place all oecurences of string y with .s u' eplace all occurrences of string u with 000 replace all occurrences of stritng an with- th0+3 replace all occurrences of string th with 10+3 o"7654 replace all occurrences of string o with 7654 replace all occurrences of string 9 with 2 replace all occurrences of string ck with X4 For esample the cipber for nethane is n2 200+3-72( 20. Here is how we get thi "sethane'.replace''90 90) 90.9(than9(.9(.replace'an,-?') 9(90I0+3-799 m9C 9(103-99(replace(9, '2) %2(+2(!0.3-7202( Deerypting will involve using the rules in reverse oader. Your program st use two functions: Write one fanction encrypt(vord) that takes as an argument a string in plain English, and returns a ciphered version of it as a string Write a second function decrypt(uord) that does the reverse takes a string in cipher and returns the plain English vension of it Both functions will be very similar in stracture, but they will use the string replacement rules in different onder. Yon can now test whether your fumctions are correct hy Erst encrypting a string, and then decrypting, The result should be identical to the original string (assming the replacement rules are not ambigaotus) Use these fanctions to implement the above program. We will test your cle for the abore es as well as a range of different values

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

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions