#include #include #include using namespace std; class Caesar { public: void encrypt(char *inp,char *out,int key); void decrypt(char *inp,char *out,int key); void readText(char *inp); void encrypt1();...



#include
#include
#include
using namespace std;
class Caesar
{
public: void encrypt(char *inp,char *out,int key);
void decrypt(char *inp,char *out,int key);
void readText(char *inp);
void encrypt1();
void decrypt1();
};
void Caesar::encrypt(char *inp,char *out,int key)
{
ifstream input;
ofstream output;
char buf;
input.open(inp);
output.open(out);
buf=input.get();
while(!input.eof())
{
if(buf>='a'&&buf<>
{
buf-='a';
buf+=key;
buf%=26;
buf+='A';
}
output.put(buf);
buf=input.get();
}
input.close();
output.close();
readText(inp);
readText(out);
}
void encrypt1()
{
char message[100], ch;
int i, key;
ofstream myfile ("encrypt.dat");


cout < "enter="" a="" message="" to="" encrypt:="">
cin>>message;
cout < "\nenter="" key:="">
cin >> key;


for(i = 0; message[i] != '\0'; ++i){
ch = message[i];


if(ch >= 'a' && ch <=>
ch = ch + key;


if(ch > 'z'){
ch = ch - 'z' + 'a' - 1;
}


message[i] = ch;
}
else if(ch >= 'A' && ch <=>
ch = ch + key;


if(ch > 'Z'){
ch = ch - 'Z' + 'A' - 1;
}


message[i] = ch;
}
myfile < message[i]="">< "="" "="">
}


}
void decrypt1()
{
char message[100], ch;
int i, key;
ofstream myfile ("decrypt.txt");
cout < "enter="" a="" message="" to="" decrypt:="">
cin>>message;
cout < "enter="" key:="">
cin >> key;


for(i = 0; message[i] != '\0'; ++i){
ch = message[i];


if(ch >= 'a' && ch <=>
ch = ch - key;


if(ch <>
ch = ch + 'z' - 'a' + 1;
}


message[i] = ch;
}
else if(ch >= 'A' && ch <=>
ch = ch - key;


if(ch > 'a'){
ch = ch + 'Z' - 'A' + 1;
}


message[i] = ch;
}
myfile < message[i]="">< "="" "="">
}
}


void Caesar::decrypt(char *inp,char *out,int key)
{
ifstream input;
ofstream output;
char buf;
input.open(inp);
output.open(out);
buf=input.get();
while(!input.eof())
{
if(buf>='A'&&buf<>
{
buf-='A';
buf+=26-key;
buf%=26;
buf+='a';
}
output.put(buf);
buf=input.get();
}
input.close();
output.close();
readText(inp);
readText(out);
}
void Caesar::readText(char *inp)
{
ifstream input;
char buf;
input.open(inp);
cout<"\n\n><---><><" ---="">\n";
buf=input.get();
while(!input.eof())
{
cout<>
buf=input.get();
}
input.close();
}
int main()
{
Caesar a;
int choice,key,ch;
char inp[30],out[30];
cout<"\n\n 1.="" using="" file\n="" 2.="" using="" keyboard="" input\n\n="" select="" choice(1="" or="" 2):="">
cin>>ch;
if(ch==1){
cout<"\n enter="" input="" file:="">
cin>>inp;
cout<"\n enter="" output="" file:="">
cin>>out;
cout<"\n enter="" key:="">
cin>>key;


cout<"\n\n 1.="" encrypt\n="" 2.="" decrypt\n\n="" 3.="" exit.select="" choice(1="" or="" 2.="" press="" 0="" for="" exit):="">
cin>>choice;
do{
switch(choice){
case 1:


a.encrypt(inp,out,key);
break;


case 2:


a.decrypt(inp,out,key);
break;
case 3:
exit(0);


default: cout<"\n\n unknown="">
}
}while(choice!=0);
}
else if(ch==2)
{
cout<"\n\n 1.="" encrypt\n="" 2.="" decrypt\n\n="" select="" choice(1="" or="" 2):="">
cin>>choice;
do{
switch(choice){
case 1:


encrypt1();
break;


case 2:


decrypt1();
break;


default: cout<"\n\n unknown="">
}
}while(choice!=0);
}


}





Question



for the c++ program above add comments to each line of code

Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here