Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use C++ to write the following program, the topic is I/O stream: In this assignment, you will be creating a modified form of the Caesar

Use C++ to write the following program, the topic is I/O stream:

In this assignment, you will be creating a modified form of the Caesar cipher, the simplest and earliest known substitution cipher. In this cipher, each letter is replaced (or substituted) by the k th letter, where k is a numerical key that indicates which letter to substitute for. For example, if k = 3, then the letter A would be replaced with the letter D, B would be replaced by E, and so forth. This cipher does wrap around, so in this example, the letter X would be replaced by the letter A, Y would be replaced by B, and Z by C. Mathematically, each letter can be given a number and a formula can be derived to encrypt for c (ciphertext) and m (plaintext) using k (key) as follows:

c = (m + k) % 26

m = (26 + c - k) % 26

Note that formula assumes A is 0, B is 1, and so forth with nothing to distinguish between uppercase A and lowercase a. Since you will most likely be using the character ASCII values, you will have to modify these formulas to fit your needs, but this should give you a place to start.

The purpose of this programming project is write a C++ program to implement a simple cryptosystem that incorporates topics related to file I/O. In particular, this programming assignment will read an input file, encrypt or decrypt the file based on the requested operation, and write the results to an output file. As with all programs in this course, your programs output should initially display the department and course number, your name, your EUID, and your e-mail address. This functionality shall be implemented using a function. Your program should then prompt the user whether he/she would like to encrypt or decrypt a file. If a valid response is not input, you are to repeatedly re-prompt the user until a valid response is input. You will then prompt the user to enter the name of the input file to read from and the output file to write the resulting plaintext or ciphertext as appropriate. If there is a problem opening the file, you will display a meaningful error and exit the program using the appropriate exit status. You may assume that the length of the file name does not exceed 32 characters (33 with the terminating null character). You will write a function to process the input file that will encrypt or decrypt the input file and write the results to an output file based on the following requirements:

1. You will prompt the user to enter a numerical key (i.e., an integer) that will be used to encrypt or decrypt the file as appropriate for the operation. You may assume that this number is positive, but it may be a large number (such as 30, which should give the same alphabetic shift as 4).

2. The files that you will encrypt or decrypt will only contain uppercase alphabetic characters (A Z), lowercase alphabetic characters (a z), numeric digits (0 9), and whitespace, which may include any white space such as a blank space, a tab, a newline character, etc.

3. The user-defined function to process the input and output files should accept at minimum two parameters, the input file stream and the output file stream, but it may utilize additional parameters as needed. You will process each file character-by-character (i.e., using the get and put member functions).

4. You will handle encryption in the following manner:

a. You will encrypt all alphabetic characters, both uppercase and lowercase, using the user-entered key. Uppercase characters should encrypt to uppercase characters and lowercase characters should encrypt to lowercase characters. For example, if the key is 3, A would be replaced with the D, B would be replaced by E, , Y would be replaced by B, and Z would be replaced by C. Similarly, if the key is 3, a would be replaced with the d, b would be replaced by e, , y would be replaced by b, and z would be replaced by c.

b. You will encrypt all digits using the user-entered key. For example, if the key is 3, 0 would be replaced with 3, 1 would be replaced with 4, , 8 would be replaced with 1, and 9 would be replaced with 2.

c. If the plaintext file contains white space, such as a blank space, a tab, or a newline character, you will simply discard (i.e., remove) the white space character in the ciphertext.

d. No other characters, such as punctuation or special characters, will be encrypted, although you may want to print out an error message and continue encrypting if it occurs, but do not write the non-valid character to the ciphertext.

e. All encrypted characters based on these requirements shall be written to the ciphertext file specified by the user.

5. You will handle decryption in the following manner:

a. You will decrypt all alphabetic characters, both uppercase and lowercase, using the user-entered key. Uppercase characters should decrypt to uppercase characters and lowercase characters should decrypt to lowercase characters. For example, if the key is 3, D would be replaced with the A, E would be replaced by B, , B would be replaced by Y, and C would be replaced by Z. Similarly, if the key is 3, d would be replaced with the a, e would be replaced by b, , b would be replaced by y, and c would be replaced by z.

b. You will decrypt all digits using the user-entered key. For example, if the key is 3, 3 would be replaced with 0, 4 would be replaced with 1, , 1 would be replaced with 8, and 2 would be replaced with 9.

c. No other characters, such as white space, punctuation, or special characters, will be decrypted, although you may want to print out an error message and continue decrypting if it occurs, but do not write the nonvalid character to the plaintext.

d. All decrypted characters based on these requirements shall be written to the plaintext file specified by the user.

***Thats my assignment if someone could guide me in some way dont expect you to do it for me but guide me in the right direction cause im really confused

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

More Books

Students also viewed these Databases questions

Question

At what level(s) was this OD intervention scoped?

Answered: 1 week ago