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

Need help in c++, using xcode, please and thank you Write a complete program tha

ID: 3742569 • Letter: N

Question

Need help in c++, using xcode, please and thank you

Write a complete program that performs encryption/decryption of a text file. Encryption means you need to scramble the words of a file to become secure. Decryption means you need to apply some rules to an encrypted file in order to find the original file with its original content. An example of encryption is to replace each letter in a file with its consecutive letter in the alphabet. Therefore, ‘a’ is replaced by ‘b’, ‘b’ is replaced by ‘c’ and so on and finally ‘z’ is replaced by ‘a’. Thus, if the file contains the following message:

           I am a student at cssss

The encrypted message becomes:

           J bn b tuvefou bu dtvtn

Then if you get this encrypted message and the key is 1, it means you need to shift the alphabets in the decrypted message by 1 to the left to get the original message back.

This method is called “rot1” indicating that every alphabet rotates by 1 during the encryption. Similarly, rot10 means every alphabet should be rotated by 10 during encryption.

Another method of encryption is to create cryptogram. A cryptogram is a message or word where each letter is replaced with another letter. For example, the string:

           The birds name was squawk

might be scrambled to form

           xms kbypo zhqs fho obrhfu

Note that space or any punctuation is not scrambled. In this particular case, ‘T’ was replaced with ’x’, each ‘a’ was replaced with ‘h’. etc. We assume there is no difference between lower case or uppercase. Therefore, you must turn all of the letters of a word into lower case before encrypt it. For example, if your work is “McMaster”, the function (word = “tolower(“McMaster”)) makes word to be equal to “mcmaster”.

Your job is to write a driver program (look at the program guide to see how to create a driver program) that performs different types of encryption or description. First, you need to ask the user to see if the user wants to do encryption or decryption. If the user wants to do encryption, you should find out if the user wants to use “rot” method or cryptogram method. If the user selects the “rot” method, you need to ask for the encryption key. For example, entering 15, means that the user wants to use “rot15” method to do encryption. If the user selects the cryptogram method, you should open the cryptogram text file called “CryptoKey” where the cryptogram string is stored. The cryptogram string should contain a string of 26 letters where the first letter corresponds to letter ‘a’, the second letter corresponds to letter ‘b’ and so on. For example, your cryptogram file may contain the following message.

              uhtxvdepqlzfonkcrwyijsgabm

which means ‘u’ corresponds to ‘a’, ‘h’ corresponds to ‘b’ and … and finally ‘m’ corresponds to ‘z’.

The same procedure should be followed for decryption. You need to ask the user which method the user wants to use (rot or cryptogram) for encryption. Then write the routines that takes an encrypted file and does the decryption to get the original file back.

You are responsible to use string and vector class in this program. For encryption, you need to read the file to be encrypted into a vector of string and place the words (one word per element) into a vector. Then read the elements of your vector one by one and do the encryption and place the encrypted word into another vector. Finally write the content of encrypted vector to an output file.

For decryption, you need to do the same process which is read the file that contains the encrypted information and place the encrypted words one by one into a vector. Then create another vector so that as you decrypt the information you can place the decrypted words into another vector. Finally, the vector that contains the decrypted words (original message) should be written to an output file.

Here is a message you can do your test:

Psychology is the study of mind and behavior [1][2]. It is an academic discipline and an applied science which seeks to understand individuals and groups by establishing general principles and researching specific cases [3][4]. In this field, a professional practitioner or researcher is called a psychologist and can be classified as a social, behavioral, or cognitive scientist. Psychologists attempt to understand the role of mental functions in individual and social behavior, while also exploring the physiological and biological processes that underlie cognitive functions and behaviors. Psychologists explore concepts such as perception, cognition, attention, emotion, intelligence, phenomenology, motivation, brain functioning, personality, behavior, and interpersonal relationships, including psychological resilience, family resilience, and other areas. Psychologists of diverse orientations also consider the unconscious mind. [5] Psychologists employ empirical methods to infer causal and correlational relationships between psychosocial variables. In addition, or in opposition, to employing empirical and deductive methods, some especially clinical and counseling psychologists at times rely upon symbolic interpretation and other inductive techniques. Psychology has been described as a "hub science", [6] with psychological findings linking to research and perspectives from the social sciences, natural sciences, medicine, humanities, and philosophy

Place the above message in a text file called “Original.txt” and test your program based on the following:

Execute your program to run the driver routine. Then do the following:

Encrypt the original message using “rot21” (shifting every alphabet to the right 21) and call the file EncryptRot.txt

Encrypt the original message using the following cryptogram and call the file EncryptCrypto.txt

           yihtqkcdplzuvwmxsgajbrfeon

Decrypt “EncryptRot.txt” file using “rot21” (shifting every alphabet to the left 21) places and call it “DecryptRot.txt”

Decrypt “EncryptCypto.txt” file using the above cryptogram and call it “DecryptCrypto.txt”

Your “DecryptRot.txt” and “DecryptCrypto.txt” should be similar (not exactly identical) to your “Original.txt” file you used for encryption. For example, in the decrypted files all words are in lower case but it is not necessarily the case in the “Original.txt” file.

Explanation / Answer

main.cpp

#include <cstdlib>
#include "Message.h"
using namespace std;

/*
* Driver program to do encryption decryption
*
*/
int main(int argc, char** argv) {
char option,ch,method;
int key;
do{
cout<<"Operation to be performed [Encryption(e)/Decryption(d)]";
cin>>option;
cout<<" Select method [Rot(r)/Cryptogram(c)]:";
cin>>method;
switch(method)
{
case 'r':
case 'R':
{
cout<<" Enter Key:";
cin>>key;
Message msg(key,option); //this class handles encryption and decryption
msg.rot(); //calls rot function to encrypt or decrypt message
}
break;
case 'c':
case 'C':
{
Message msg(0,option); //key is 0 in case of cryptogram
msg.crypto(); //calls crypto function to encrypt or decrypt message
break;
}
}   
cout<<" Do you want to continue(y/n)?";
cin>>ch;
}while(ch=='y'||ch=='Y');
return 0;
}

Message.h

#ifndef MESSAGE_H
#define MESSAGE_H

#include<string>
#include<fstream>
#include<iostream>
#include<vector>
using namespace std;

class Message {
public:
Message(int,char);
void rot();
void crypto();   
private:
int key; //key for rot method
int option; //whether rot or cryptogram
string inputFile; //name of input file
char cryptoKey[26]; //holds the cryptokey. cryptoKey[0] holds replacement character for a etc
vector <string> input; //vector for input
vector <string> output; //vector for output
void readInput();//reads input from inputfile and add to a vector
void readCryptoKey();//reads file and builds the cryptokey array
  

};

#endif /* MESSAGE_H */

Message.cpp

#include <fstream>
#include <vector>
#include<string>
using namespace std;
#include "Message.h"

Message::Message(int k,char opt) {
key=k;
option=opt;
cout<<" Enter file:";
cin>>inputFile;
//cout<<"Option:"<<option;
readInput();//reads input from inputfile and add to a vector
  
}
//read from file and add to vector
void Message::readInput()
{
string line;
ifstream in(inputFile);
if(in.is_open())
{
while(!in.eof())
{
in>>line;
input.push_back(line);   
}   
}   
else
cout<<" File not found:"<<inputFile;
}
//encrypt/decrypts according to rot method
void Message::rot()
{
string word;
ofstream out;
string outputWord;
for(int i=0;i<input.size();i++)
{
outputWord="";
word=input[i];
for(int j=0;j<word.length();j++)
{
if(option=='e')
{
if (word[j] >= 'A' && word[j] <= 'Z') //convert capital letters by wraping
{
outputWord+=(char)(((word[j] + key - 'A' + 26) % 26) + 'A');
}
else if (word[j] >= 'a' && word[j] <= 'z') //convert small letters by wraping
{
outputWord+=(char)(((word[j] + key - 'a' + 26) % 26) + 'a');
}
else
outputWord+=word[j];//wrap around
}
else
{
if (word[j] >= 'A' && word[j] <= 'Z') //decrypt capital letters by wraping
{
outputWord+= (char)(((word[j] - key - 'A' + 26) % 26) + 'A');
}
else if (word[j] >= 'a' && word[j] <= 'z') //decrypt small letters by wraping
{
outputWord+= (char)(((word[j] - key - 'a' + 26) % 26) + 'a');
}
else
outputWord+=word[j];
}
  
}   
output.push_back(outputWord);   
}
if(option=='e')
{
out.open("EncryptRot.txt");
for(int i=0;i<output.size();i++)
out<<output[i]<<" ";//write to file
}
else
{
out.open("DecryptRot.txt");
for(int i=0;i<output.size()-1;i++)
out<<output[i]<<" ";
}
  
}
//encrypt/decrypts according to crypto method
void Message::crypto()
{
readCryptoKey();//read crypto keys to array
string word;
ofstream out;
string outputWord;
for(int i=0;i<input.size();i++)
{
outputWord="";
word=input[i];
  
for(int j=0;j<word.length();j++)
{
if(option=='e')
{
if(tolower(word[j])>= 'a' && tolower(word[j]) <= 'z') //find appropriate cryptokey
outputWord+=cryptoKey[tolower(word[j])-'a'];
else
outputWord+=word[j];
}
else
{
if(word[j]>= 'a' && word[j] <= 'z') //find appropriate cryptokey for decryption
{
for(int k=0;k<26;k++)
if(cryptoKey[k]==word[j])
outputWord+=char(k+97);
}
else
outputWord+=word[j];   
}
  
}   
output.push_back(outputWord);   
}
if(option=='e')
{
out.open("EncryptCrypto.txt");
for(int i=0;i<output.size();i++)
out<<output[i]<<" ";
}
else
{
out.open("DecryptCrypto.txt");
for(int i=0;i<output.size()-1;i++)
out<<output[i]<<" ";
}
  
}

//read cryptokey file and build cryptoKey array
//cryptoKey[0] is covert alphabet for a
void Message::readCryptoKey()
{
char ch;
ifstream in("CryptoKey.txt");
int i=0;
if(in.is_open())
{
while(!in.eof())
{
ch=char(in.get());
cryptoKey[i]=ch;
i++;
}   
}   
else
cout<<" File not found:"<<"CryptoKey.txt";
}

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