Vigenere.h #include using namespace std; //Create class Vigenere class Vigenere { //Members private: string key; //Functions public: //Constructor Vigenere(); //Setter and getter void setKey(string key); string getKey(); //Convert into upper case string toUpperCase(string k); //Encrypt string encrypt(string word); //Decrypt string decrypt(string word); }; Vigenere.cpp //Implementation #include "Vigenere.h" //Constructor Vigenere::Vigenere() {    this->key = ""; } //Setter and getter void Vigenere::setKey(string key) {    this->key = key; } string Vigenere::getKey() {    return key; } //Convert into upper case string Vigenere::toUpperCase(string k) {    for (int i = 0; i < k.length(); i++) {        if (isalpha(k[i])) {            k[i] = toupper(k[i]);        }    }    return k; } //Encrypt string Vigenere::encrypt(string word) {    return key;    string output = "";    for (int i = 0, j = 0; i < word.length(); i++) {        char c = word[i];        if (c >= 'a' && c <= 'z') {            c += 'A' - 'a';        }        else if (c < 'A' || c>'Z') {            continue;        }        output += (c + key[j] - 2 * 'A') % 26 + 'A';        j = (j + 1) % key.length();    }    return output; } //Decrypt string Vigenere::decrypt(string word) {    string output = "";    for (int i = 0, j = 0; i < word.length(); i++) {        char c = word[i];        if (c >= 'a' && c <= 'z') {            c += 'A' - 'a';        }        else if (c < 'A' || c>'Z') {            continue;        }        output += (c - key[j] + 26) % 26 + 'A';        j = (j + 1) % key.length();    }    return output; } Message.h #include #include "Vigenere.h" //Create class class Message { //Members private: vectorwords; Vigenere v; //Functions public: //Constructor Message(string key); //Encrypt void encryptWord(char* token); //Decrypt void decryptWord(char* token); //Make a file void makeFile(string fileName); //Display void showWords(); }; Message.cpp //Implementation of Message class #include "Message.h" #include #include //Constructor Message::Message(string key) {    v.setKey(key); } //Encrypt void Message::encryptWord(char* token) {    words.push_back(v.encrypt(token)); } //Decrypt void Message::decryptWord(char* token) {    words.push_back(v.decrypt(token)); } //Make a file void Message::makeFile(string fileName) {    ofstream out(fileName);    for (int i = 0; i < words.size(); i++) {        out << words[i] << " ";    }    out << endl;    out.close(); } //Display void Message::showWords() {    for (int i = 0; i < words.size(); i++) {        cout << words[i] << " ";    }    cout << endl; } VigenerCypherDriver.cpp #include #include #include #include "Message.h" //Function prototype int getMenu(); int main() { string key, filename, line; char buff[1000]; char* token = NULL; //Prompt for key cout << "Enter an encryption/decryption key:\n"; getline(cin, key); cout << endl; //Create message object Message msg(key); //Get choice int opt = getMenu(); //Loop until quit while (opt != 3) {  if (opt == 1) {   cout << "\nEnter the name of the file to encrypt: ";   getline(cin, filename);   ifstream in(filename);   if (!in) {    cout << "File not found!!!\n";   }   else {    while (!in.eof()) {     in.getline(buff, 1000);     const char* delim = " ";     char* next_token;     token = strtok_s(buff, delim, &next_token);     while (token) {      msg.encryptWord(token);      token = strtok_s(NULL, delim, &next_token);     }    }    in.close();    cout << "\nA new file will be created that contains the encrypted message.\n\n";    cout << "Please enter the name of the new file to create: ";    getline(cin, filename);    msg.makeFile(filename);    cout << "\n\nEncrypted file:\n";    msg.showWords();     }  }  else if (opt == 2) {   cout << "\nEnter the name of the file to decrypt: ";   getline(cin, filename);   ifstream in(filename);   if (!in) {    cout << "File not found!!!\n";   }   else {    while (!in.eof()) {     in.getline(buff, 1000);     const char* delim = " ";     char* next_token;     token = strtok_s(buff, delim, &next_token);     while (token) {      msg.decryptWord(token);      token = strtok_s(NULL, delim, &next_token);     }    }    in.close();    cout << "\nA new file will be created that contains the decrypted message.\n\n";    cout << "Please enter the name of the new file to create: ";    getline(cin, filename);    msg.makeFile(filename);    cout << "\n\nDecrypted file:\n";    msg.showWords();   }  }  cout << endl;  opt = getMenu(); } cout << "\n\nThank You!!\n"; return 0; } //Implementation of menu unction int getMenu() { int opt; cout << "\tVigenre Cypher\n\n Main Menu\n\n1 - Encrypt File\n2 - Decrypt File\n3 - Quit\n\n"; cout << "Selection: "; cin >> opt; while (opt < 1 || opt>3) {  cout << "\nWrong choice!!!\n\nSelection: ";  cin >> opt; } cin.ignore(); return opt; } Why wont it work Please help me

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Vigenere.h

#include<string>
using namespace std;
//Create class Vigenere
class Vigenere {
//Members
private:
string key;
//Functions
public:
//Constructor
Vigenere();
//Setter and getter
void setKey(string key);
string getKey();
//Convert into upper case
string toUpperCase(string k);
//Encrypt
string encrypt(string word);
//Decrypt
string decrypt(string word);
};

Vigenere.cpp

//Implementation
#include "Vigenere.h"
//Constructor
Vigenere::Vigenere() {
   this->key = "";
}
//Setter and getter
void Vigenere::setKey(string key) {
   this->key = key;
}
string Vigenere::getKey() {
   return key;
}
//Convert into upper case
string Vigenere::toUpperCase(string k) {
   for (int i = 0; i < k.length(); i++) {
       if (isalpha(k[i])) {
           k[i] = toupper(k[i]);
       }
   }
   return k;
}
//Encrypt
string Vigenere::encrypt(string word) {
   return key;
   string output = "";
   for (int i = 0, j = 0; i < word.length(); i++) {
       char c = word[i];
       if (c >= 'a' && c <= 'z') {
           c += 'A' - 'a';
       }
       else if (c < 'A' || c>'Z') {
           continue;
       }
       output += (c + key[j] - 2 * 'A') % 26 + 'A';
       j = (j + 1) % key.length();
   }
   return output;
}
//Decrypt
string Vigenere::decrypt(string word) {
   string output = "";
   for (int i = 0, j = 0; i < word.length(); i++) {
       char c = word[i];
       if (c >= 'a' && c <= 'z') {
           c += 'A' - 'a';
       }
       else if (c < 'A' || c>'Z') {
           continue;
       }
       output += (c - key[j] + 26) % 26 + 'A';
       j = (j + 1) % key.length();
   }
   return output;
}
Message.h

#include<vector>
#include "Vigenere.h"
//Create class
class Message {
//Members
private:
vector<string>words;
Vigenere v;
//Functions
public:
//Constructor
Message(string key);
//Encrypt
void encryptWord(char* token);
//Decrypt
void decryptWord(char* token);
//Make a file
void makeFile(string fileName);
//Display
void showWords();
};

Message.cpp

//Implementation of Message class
#include "Message.h"
#include<fstream>
#include<iostream>
//Constructor
Message::Message(string key) {
   v.setKey(key);
}
//Encrypt
void Message::encryptWord(char* token) {
   words.push_back(v.encrypt(token));
}
//Decrypt
void Message::decryptWord(char* token) {
   words.push_back(v.decrypt(token));
}
//Make a file
void Message::makeFile(string fileName) {
   ofstream out(fileName);
   for (int i = 0; i < words.size(); i++) {
       out << words[i] << " ";
   }
   out << endl;
   out.close();
}
//Display
void Message::showWords() {
   for (int i = 0; i < words.size(); i++) {
       cout << words[i] << " ";
   }
   cout << endl;
}

VigenerCypherDriver.cpp

#include <iostream>

#include<fstream>

#include<string>

#include "Message.h"

//Function prototype

int getMenu();

int main()

{

string key, filename, line;

char buff[1000];

char* token = NULL;

//Prompt for key

cout << "Enter an encryption/decryption key:\n";

getline(cin, key);

cout << endl;

//Create message object

Message msg(key);

//Get choice

int opt = getMenu();

//Loop until quit

while (opt != 3) {

 if (opt == 1) {

  cout << "\nEnter the name of the file to encrypt: ";

  getline(cin, filename);

  ifstream in(filename);

  if (!in) {

   cout << "File not found!!!\n";

  }

  else {

   while (!in.eof()) {

    in.getline(buff, 1000);

    const char* delim = " ";

    char* next_token;

    token = strtok_s(buff, delim, &next_token);

    while (token) {

     msg.encryptWord(token);

     token = strtok_s(NULL, delim, &next_token);

    }

   }

   in.close();

   cout << "\nA new file will be created that contains the encrypted message.\n\n";

   cout << "Please enter the name of the new file to create: ";

   getline(cin, filename);

   msg.makeFile(filename);

   cout << "\n\nEncrypted file:\n";

   msg.showWords();

 

  }

 }

 else if (opt == 2) {

  cout << "\nEnter the name of the file to decrypt: ";

  getline(cin, filename);

  ifstream in(filename);

  if (!in) {

   cout << "File not found!!!\n";

  }

  else {

   while (!in.eof()) {

    in.getline(buff, 1000);

    const char* delim = " ";

    char* next_token;

    token = strtok_s(buff, delim, &next_token);

    while (token) {

     msg.decryptWord(token);

     token = strtok_s(NULL, delim, &next_token);

    }

   }

   in.close();

   cout << "\nA new file will be created that contains the decrypted message.\n\n";

   cout << "Please enter the name of the new file to create: ";

   getline(cin, filename);

   msg.makeFile(filename);

   cout << "\n\nDecrypted file:\n";

   msg.showWords();

  }

 }

 cout << endl;

 opt = getMenu();

}

cout << "\n\nThank You!!\n";

return 0;

}

//Implementation of menu unction

int getMenu() {

int opt;

cout << "\tVigenre Cypher\n\n Main Menu\n\n1 - Encrypt File\n2 - Decrypt File\n3 - Quit\n\n";

cout << "Selection: ";

cin >> opt;

while (opt < 1 || opt>3) {

 cout << "\nWrong choice!!!\n\nSelection: ";

 cin >> opt;

}

cin.ignore();

return opt;

}

Why wont it work Please help me

Main Menu
1 - Encrypt File
2 - Decrypt File
3 - Quit
Selection: 2
Enter the name of the file to decrypt: The Lords Prayer (Encrpyted).txt
File not found!!!
Vigenre Cypher
Main Menu
1 Encrypt File
2 Decrypt File
3 - Quit
Selection:
Transcribed Image Text:Main Menu 1 - Encrypt File 2 - Decrypt File 3 - Quit Selection: 2 Enter the name of the file to decrypt: The Lords Prayer (Encrpyted).txt File not found!!! Vigenre Cypher Main Menu 1 Encrypt File 2 Decrypt File 3 - Quit Selection:
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Data members
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education