Choice #3 You will prompt the user for the name of a file containing an encoded text (i.e. a file containing number pairs). Your program will read the file and decode the the text using the indexes pairs given for each character in the word and the text file chosen for Choice #1. If no file has been chosen for Choice #1 (i.e. the users goes directly to Choice #3 without first choosing Choice #1), you will prompt the user to enter a cipher text and read it into memory (presumably by calling the function that would be called by Choice #1). Spaces found in the file are to be treated as spaces in the decoded text. You can assume that the number of characters in the encoded text file is 5000 or less, including any carriage returns or NULL terminator characters. Once the text is decoded, print the message to standard output.
I Need Help on Choice #3, Thank you!!
You should approach this assignment in several parts. The first part will be to write a menu
driven program that prompts the user for the following actions:
1) Read in the name of a text file to use as a cipher key
2) Create a cipher using the input text file (and save the result to a file)
3) Decode an existing cipher (prompt user for a file to read containing the cipher text)
4) Exit the program
For each choice, create a stub function that will be completed in the remaining steps.
After testing your menu, continue to fill in the stub functions with the following specifications:
Choice #1
For this menu choice, you will prompt the user for the name of a cipher text file (such as the
Declaration of Independence). You will read this text file line by line, and place each word, in
order, in an array of char strings. As you copy each word into the array, you will keep a running
count of the number of words in the text file and convert the letters of each word to lower case.
You may assume that you will use no more than the first 5,000 words in the text, and no more than
the first 15 characters in a word. However, there is no guarantee that the text will have 5000 words
or less and any word in the text is 15 characters or less.
Choice #2
If no file has been chosen for Choice #1 (i.e. the user goes directly to Choice #2 without first
choosing Choice #1), you will first prompt the user to enter a cipher text and read it into memory
(presumably by calling the function that would be called by Choice #1). You will prompt the user
to enter a secret message (in plain text - such as "Computer Science is the best major at GMU!")
that is terminated by pressing the "Enter" key. You can assume that the length of this message will
be less than 1500 characters (including the carriage return and NULL terminator). You will then
parse this message, character by character, converting them to lower case as you go, and find
corresponding characters in the words found in the key text word array. You can do this by going
through each word in the word array, and then each character in each word, until you find a match
with the current message character.
There are more efficient ways to perform this operation, and you are encouraged to implement
them instead of the given method. Once a character match is found, you will write the index of the
word and the index of the character to a character string that you will later write out to a text file.
Spaces are to be placed into the text as found in the message and will be used to delimit the separate
words in the secret message. Once the message has been encoded, prompt the user for the name of
a file to save the encoded message to, and save it to that file.
Choice #3
You will prompt the user for the name of a file containing an encoded text (i.e. a file containing
number pairs). Your program will read the file and decode the the text using the indexes pairs
given for each character in the word and the text file chosen for Choice #1. If no file has been
chosen for Choice #1 (i.e. the users goes directly to Choice #3 without first choosing Choice #1),
you will prompt the user to enter a cipher text and read it into memory (presumably by calling the
function that would be called by Choice #1). Spaces found in the file are to be treated as spaces in
the decoded text. You can assume that the number of characters in the encoded text file is 5000 or
less, including any carriage returns or NULL terminator characters. Once the text is decoded, print
the message to standard output.
Choice #4
Exit the program.
Additional Specifications
• In order to introduce some "randomness" in the specific character encoding, you
will generate a random number i from 0..9 inclusive (use the last four digits of your
G Number as the seed), and use the ith instance of that character found in the text.
(If fewer than i instances of the character is found in the text, loop back and
continue the search from the beginning of the document.)
Example: Suppose the letter to encode is a 'c'. Using the sentences just above, we
find that there are the following 'c' characters:
§ In order to introduCe some "randomness" in the speCifiC CharaCter
enCoding, you will generate a random number i from 0..9 inClusive (use the
last four digits of your G Number as the seed), and use the ith instanCe of that
CharaCter found in the text.
§ If the random number returns 6, then you will use the 'c' from the word
"inclusive." (Start counting from 0). If the random number returns 2, you
would the second c found in the word "specific."
• If a given character in the secret message is not found in any word of the text,
replace that character with the '#' character in the encoded text (a single '#'
character replaces a word/position pair).
• You can assume that the message to encrypt or decrypt will be less than 1500
characters.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images