Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Overview: You have been tasked with encoding and decoding supersecret information for a government organization. We will be using a substitution cipher in this project.

Overview: You have been tasked with encoding and decoding supersecret information for a government organization. We will be using a substitution cipher in this project. A substitution cipher with a unit of a letter is a method of encoding by which specific letters in a text are replaced with a different letter everytime. For example, the letter a is replaced with d and the letter b is replaced with a and so forth throughout the text.

In this project you will be reading the cipher key from a file. This file will consist of 26 numbers, each on a separate line, with the values 0 through 25. The first line of the file will be the letter that replaces a, the second line will be the letter that replaces b and so forth.

For example, suppose the first few lines of the file are as follows...

1

2

3

0

This would mean that any letter a that we want to encode would become b (1, as we start counting at 0). Then b would become c (2), c would become d(3) and d would become a (0).

Using this fragment of the file, suppose we want to encode the text

dadacad

This should result in the text...

ababdba

Suppose that we wanted to go the opposite way (convert encoded text back to the original). We would start with the encoded text, in our example it was...

ababdba

Then we would want to see what gave us an a. We could look through the array that we had until we find the element that gave us an a. That position that we are at would indicate what we should substitute for a. You could do this for every element in the array and actually generate a key to go backwards in one step. In this example, our key would be

3

0

1

2

Now that we have covered the basics, lets go into specifics.

Specification: In this project, start by taking a filename from the user. Then write a function that takes in a string (this filename), an array and a size of the array (in practice for this project the array sizes will all be 26, but you should get into the habit of always passing array sizes to functions). This function should read from the file and save the resulting key data into that array. This is our key to encode with. The function should return a value indicating if it was successful when reading from the file.

You should then write a second function that takes in two arrays and the size of both of the arrays. This function should take in the encoding key array from the previous project and an array that will hold the decoding key. It should then use the encoding key to set the elements of the decoding array.

Once this is done, display both arrays to the user.

Now prompt the user on whether or not they want to encode or decode (for this, give a menu, 1 for encode, 2 for decode). Then prompt them for a string. This string should not contain anything other than alphabetic letters, so no spaces, punctuation or digits. The program should then either decode or encode the text. To do this you should have a function that takes in the appropriate array, the string and a key array and then outputs the appropriate string information.

Example:

Welcome to supersecret encoding utility!

Please enter a filename with a key: cipherencoder.key

What do you wish to do:

1) Encode text

2) Decode text

Please enter your choice(1,2):1

Thank you, please enter your text to encode: dadacad

The ciphertext is: ababdba

Functions required for this project:

int readEncodingCipher(string filename, int encodeKey[], int size);

void produceDecodingCipher(int encodeKey[], int decodeKey[], int size);

void useKeyOnString(int key[], int size, string text);

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

Knowledge Discovery In Databases

Authors: Gregory Piatetsky-Shapiro, William Frawley

1st Edition

0262660709, 978-0262660709

More Books

Students also viewed these Databases questions

Question

7. Define cultural space.

Answered: 1 week ago

Question

8. Describe how cultural spaces are formed.

Answered: 1 week ago