Create a program to encode or decode a message using the Vig
Create a program to encode or decode a message using the Vigenère Cipher. The cipher consists of a message and a code word. The code word is any string of characters known only to the coder and decoder. The code word string must not have any spaces and cannot be longer than the used alphabet (26 for our case). The message to be coded or decoded can be any length, but must only contain letters and spaces.
Your program should prompt the user first as to whether the message should be encoded or decoded. Then a prompt for the message and the code word. The message and code word must be checked to ensure they are able to be coded or decoded based on the criteria in the first paragraph. If they cannot be used, an appropriate response should be output to the user (i.e. error message with the error stated). When an error is encountered re-prompt the user for their input until something is entered that can be used (this is shown in the first example below, where a question mark was put in and the program re-prompted the user for the message, and the last example where a space is in the codeword). After the inputs have been validated the program should either encode or decode the message. Then it should display the results of the encoded or decoded message. The encoded and decoded messages must retain the same spacing as they did before the encryption/decryption. The program should run multiple times until the user has no more messages to code or decode.
Use the test cases below to test your program. The decode messages you can simply copy and paste into MATLAB.
a. Encode
i. Message: This is the first message ; Codeword: first
ii. Message: The eagle flies at midnight ; Codeword: eagle
iii. Message: #TheCoolestMessageEver ; Codeword: hashtag
iv. Message: The 4th message is not very interesting ; Codeword: four
v. Message: THIS MESSAGE IS IN ALL CAPS ; Codeword: CAPS
b. Decode
i. Message: a pk s hshtp kew lwyl agctq ld bg usf hshtp kew lwgfvq ; Codeword: spy
ii. Message: zowk tyzwygslbl by kiw mnl tjbjhm syzlf ztrscoxku ; Codeword; gh0st
iii. Message: jvq oeuj diqn uqbff k oqvxermer wjeum ; Codeword: chuck’s
iv. Message: owy us escy utsuts ; Codeword: spa ces
v. Message: wvvw lg vx ; Codeword: done
The test cases that contain errors should display the error and then be retyped without the error.
Solution
The following C++ program follows or has following functionality.
Save or Load the encrypted data
Adding or modifying the key phrase at any time , were re entery of the data is not required.
The save option is mainly used to as back up of both encrypted or decrypted datas.
Thus the class object is created , the eash key/crypted/decrypted messages are stored in it.
/* inclusion of the lib file*/
# inclue<iostream>
#include\"crypter3.h\"
/*defining the crypter3*/
#ifndef CRYPTER3_H /* creating the encryption and decryption conditions.
# define CRYPTER_H
Class Crypter /* creation of new class
{
Private: /* creation of the private class*/
std::string key // variable declaration type of string
std:: string doded; / variable declaration type of string
std:: string decoded; / variable declaration type of string
public: /*creation of the public class
Crypter(); // functional class
-Crypter();
void setKey(std::string newkey); //variable declarations
void set Coded(std:: string newCoded);
void SetDecoded (std :: stringnewDecoded);
void encode(); // calling function
void decode(); // calling function
std::string viewedCoded(); // declaration as well as calling function
std:: string viewedDecoded;// Declaration as well as caling function
};
#endif // close of if statement
int main()
{
std :: sting key; // variable declaration
std :: string text; // variable declaration
std :: string filename = \"Cryptfile.bin\"; // assiging the bin file to the fiename
std :: cout<< \"\ cipher-\" <<std::end1; // printout statement , displayed in the new line
Crypter Crypt;// creating the object of crypting and decrypting
int solution;
do // using do statement
{
std::cout<<
\"\ Choose any of the below option:\ \"
\"00- EXIT\ \"
\"11-ADD KEY\ \"
\"22- ADDING TEXT \ \"
\"33-ENCRYPTION AND VIEWING THE DATA \ \"
\"44-DECRYTION AND VIEWING THE DATA \ \"
\"55-LOADING THE DATA THAT ENCRYPTED \ \"
\"66-SAVING THE ENCRYPTING DATA\ \"
std::cin>>solution;
std::cin.get(); //getting the datas from the user
switch(solution) // using the switch statement
{
case 0:
std:: cout<<\"\ THANKS\" << std::end1;
break;
case 1:
std::cout<<\"Enter the key phrase:\"<<std::end1;
getline(std::cin,key);// user input is obtained and key accordingly will be displaed
crypt.setkey(key);
break;
case3:
std::cout<<\"encoded result:\"<<std::end1;
crypt.encode();
std::cout<<crypt.viewcode()
break;
default:
std::cout<<\"\ Invalid selection,\"<<std::end1;


