Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ CAESAR CIPHER BASIC FUNCTION HELP NEEDED: ENCRYPTION AND DECRYPTION Getting Started Get into your Docker development environment and change into the data directory. Downloadthelabframeworkwithgit

C++ CAESAR CIPHER BASIC FUNCTION HELP NEEDED: ENCRYPTION AND DECRYPTION

Getting Started Get into your Docker development environment and change into the data directory. Downloadthelabframeworkwithgit clone https://github.com/csc211/lab3 Type cd lab3 followed by ls You will see this Readme.md along with a C++ source le (caesar.cpp) and a compile script compile You will also see two input les: one very short one called short.txt and a longer one called shakespeare.txt. You can now compile the lab by typing ./compile and it will produce an executable program called caesar. However, it wont do anything yet! Requirements I have provided an empty main() function. I have also provided function declarations char encrypt(char, int) and char decrypt(char, int). You must write the implementation of encrypt() and decrypt(), as well as handling command-line arguments and le I/O. Your program must take exactly four command-line arguments. Therstisastring,either-eor-dindicatingwhethertocallencrypt() or decrypt() respectively. The second is a number representing the key to be used for the encryption or decryption, so youll need to use atoi() to turn it into an integer. The third is a lename to read from. The fourth is a lename to write to. Your program must read from the rst le, determine whether to encrypt or decrypt the input, and write it out to the second le. Hints Its much easier to keep track of input/output streams if you dont try to read and write at the same time. I recommend reading your input into a string, processing that string, and then writing the rotated (encrypted or decrypted) result to the output le. You have seen (and used) an idiom for line-at-a-time input. Youve also seen (in class) character-at-a-time input. I strongly recommend reading your input a character at a time, so that you dont miss newline characters. Rememberthatyouveseentwowaystoconvertfromastringtoaninteger: atoi() >> from an istringstream 2 Be careful when testing your code. Properly implemented, this program will overwrite the output le. So, if you want to test encryption and decryption, youll need to be careful with lenames. Try something like: ./caesar -e 3 shakespeare.txt encrypted.txt ./caesar -d 3 encrypted.txt shake2.txt Now, how do you make sure that the decrypted le is the same as the original? Of course, you can open it in Atom and read it. But there is also the ever-useful unix diff command. Youd run this in the Docker command line just like youd run your caesar program: diff shakespeare.txt shake2.txt If it doesnt produce any output, then your program works. If you see a whole bunch of output, then the les are dierent. You would be wise to test on small inputs (like short.txt). Submitting You will submit your code on Mimir. Idioms Suppose we have a string called result, and we want to write it to a le whose name is in the string outfilename. We can do the following (note that the primary dierence from reading from a le is that we are using an ofstream instead of an ifstream): ofstream outfile(outfilename); if (!outfile.fail()){ outfile << result; outfile.close(); } else { cerr << "Could not open file " << outfilename << endl; exit(EXIT_FAILURE); }

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

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students also viewed these Databases questions

Question

State the Empirical Rule for a normal distribution.

Answered: 1 week ago

Question

suggest a range of work sample exercises and design them

Answered: 1 week ago