Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This program is to be completed in C++. ng the meaning of messages by putting th

ID: 3750478 • Letter: T

Question

This program is to be completed in C++. ng the meaning of messages by putting them in some kind of codeis something we have all done, from the "coding rings' and secret symbols of childhood to the top secrecy of military and commercial establishments' secret data. In fact, some of the earliest uses of computers were for coding, messages and coded messages. Newer coding methods are among the most interesting research areas in computer science today The Caesar Cipher nicate with his army. Caesar is ided that shifting each letter in the message One of the simplest examples of a substitution cipher is the Caesar Cipher, which is said to have been used by Julius Caesar to commu considered to be one of the first persons to have ever employed encryption for the sake of securing messages. Caesar dec would be his standard algorithm, and so he informed all of his generals of his decision, and was then able to send them secured messages. Us right), the message, Caesar Shift (3 to the RETURNTOROME would be encrypted as UHwXUQwRURPH In this example, RH and so on. Now, even if the enemy did interce pt the message, it would be useless, since only Caesar's generals could read it The Assignment Write a program to implement the Caesar Cipher Problem Write a program that will prog9- IN.txt file. Your input fle should start with a line with a single enumerated value O-encrypt and 1-decrypt. Subsequent lines will be used for the message If 'encrypt, your program am should decrypt the files contents by shifting each character (including white space) 3 values to the left If the file fails to open your program should print an error message and exit printouts should be displayed BOTH on the screen and also written to an output file named progy.OUT.xt

Explanation / Answer

#include<iostream>
#include<fstream>
#include<string>
#include<cstring>
using namespace std;
int main()
{
char fname[100];
cout<<"Enter File Name: "; // take input file name;
cin>>fname;
char command[100];
cout<<"Enter encrypt or decrypt: "; // input the command
cin>>command;
string line,ans_line;
ifstream infile(fname);
ofstream outfile("output"); // open output file

if(infile.good()) // if input file exist
{
if(strcmp(command,"encrypt")==0) // if command was encrypt
{
while(getline(infile,line)) // for each line in input file
{
// cout<<line<<endl;
for(int i=0;i<line.size();i++) // for each character of a line
{
line[i]= line[i]+3; // shift right
}
outfile<<line<<endl; // print the line in the output file
}

}
else if(strcmp(command,"encrypt")==0)
{
while(getline(infile,line))// for each line in input file
{
// cout<<line<<endl;
for(int i=0;i<line.size();i++) // for each character in line shift left
{
line[i]= line[i]-3;
}
outfile<<line<<endl; // print the line in output file
}
}
else
{
cout<<"Error: Bad Command."<<endl; // if any other command show error
}
}
else
cout<<"Error: File did NOT open."<<endl; /// show error if file is not opened

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote