Question

This is my assignment prompt

Programming Assignment #6 Help Me Find The Secret Message Description: This assignment will require that you read in an encrya. C. a. c. 2. The program will prompt the user for the following information: The name of encrypted file. b. The name of theThis is an example of the input and outputencryted Message2 - Notepad File Edit Format View Help 2 rtqitcookpikucyguqog rawTextSample2 - Notepad File Edit Format Vie

This is what I have so far

MakeLists.txt main.cpp C. ShiftCipher.cpp #include <iostream> #include fstream #include <string> #include ShiftCipher.h uskeLists.txt main.cpp &.. ShiftCipher.cpp ShiftCipher cipher; //TODO: get the encrypted file name encrypted_name = getEncrypteMakeLists.txt main.cpp 6. ShiftCipher.cpp } string getEncryptedFileName({ //TODO: Add code to ask the user for the encryptedMakeLists.txt e main.cpp C. ShiftCipher.cpp string getDecryptedFileName(){ //TODO: Add code to ask the user for the decryptedMakeLists.txt c. main.cpp ShiftCipher.cpp C++ #include ShiftCipher.h ShiftCipher::ShiftCipher() { //TODO: Add code to set aP akeLists.txt Emain.cpp C# ShiftCipher.cpp // TODO: add code to set the offset provided by the user offset = messageoffset;What is the 3rd ToDo in the main.cpp for open the files and read the encrypted message? Does the rest of the code look accurate?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Your full code

#ifndef PROHECT6_SHIFTCIPHER_H
#define PROHECT6_SHIFTCIPHER_H
#include <string>

using namespace std;

class ShiftCipher
{
public:
   ShiftCipher();
   void setOffset(int messgaeOffset);
   string Encode(string message);
   string Decode(string ciphertext);
private:
   int offset;
};
#endif // ! PROHECT6_SHIFTCIPHER_H

shiftCipher.cpp

#include"shiftcipher.h"

ShiftCipher::ShiftCipher()
{
   offset = 0;
}

void ShiftCipher::setOffset(int messageOffset)
{
   offset = messageOffset;
}

string ShiftCipher::Encode(string message)
{
   //TODO: Add code to encrypt the message
   string encodedMessage = "";
   int range = 91;
   for (size_t i = 0; i < message.length(); i++)
   {
       encodedMessage += (char)((((message[i] - 32) + offset) % range) + 32);
   }
   return encodedMessage;
}

string ShiftCipher::Decode(string ciphertext)
{
   //TODO: Add code to decrypt the message
   string decodedMessage = "";
   int range = 91;
   for (int i = 0; i < ciphertext.length(); i++)
   {
       decodedMessage += (char)((((ciphertext[i] - 32) + (range - offset)) % range) + 32);
   }
   return decodedMessage;
}

main.cpp

#include"shiftcipher.h"
#include<iostream>
#include<fstream>
#include<string>

using namespace std;

void runDecryption();
string getEncryptedFIleName();
string readEncrypterFile(string name, int &messageOffset);
string getDecryptedFileName();
void outputToFile(string name, string);

int main()
{
   runDecryption();
   system("pause");
   return 1;
}

void runDecryption()
{
   string encrypted_name, decrypted_name;
   string encrypted_message, decrypted_message;
   int offset;
   //TODO: Create a ShiftCipher object using defualt constructor
   ShiftCipher obj;

   //TODO: get the encrypted file name
   encrypted_name = getEncryptedFIleName();

   //TODO: open the enctypted file and read in the message
   encrypted_message = readEncrypterFile(encrypted_name, offset);

   //TODO: set the offset for the shift cipher
   obj.setOffset(offset);

   //TODO: decode the message using your ShiftCipher
   decrypted_message = obj.Decode(encrypted_message);

   //TODO: output the file name
   decrypted_name = getDecryptedFileName();

   //TODO: output the message to the file
   outputToFile(decrypted_name, decrypted_message);
}

string getEncryptedFIleName()
{
   string fName;
   cout << "What is the name of you encrypted file?: ";
   cin >> fName;
   return fName;
}

string readEncrypterFile(string name, int &messageOffset)
{
   ifstream inFile;
   string msg;
   inFile.open(name);
   inFile >> messageOffset;
   inFile.get();
   getline(inFile, msg);
   inFile.close();
   return msg;
}

string getDecryptedFileName()
{
   string fName;
   cout << "What is the name of you decrypted file?: ";
   cin >> fName;
   return fName;
}

void outputToFile(string name, string message)
{
   ofstream fout(name);
   cout << "message being save to " << name << "is:\n";
   cout << "\t" << message << endl;
  
   fout << message;
   fout.close();
  
}

output

rawTextSample2.txt

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
This is my assignment prompt This is an example of the input and output This is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ please Programming Assignment #6 Help Me Find The Secret Message Description: This assignment will require...

    C++ please Programming Assignment #6 Help Me Find The Secret Message Description: This assignment will require that you read in an encrypted message from a file, decode the message, and then output the message to a file. The encryption method being used on the file is called a shift cipher (Info Here). I will provide you with a sample encrypted message, the offset, and the decrypted message for testing. For this project I will provide you main.cpp, ShiftCipher.h, and ShiftCipher.cpp....

  • MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment:...

    MUST WRITE IN C++ Objective: Learn how to design classes using abstract classes and inheritance Assignment: In cryptography, encryption is the process of encoding a message or information in such a way that only authorized parties can access it. In this lab you will write a program to decode a message that has been encrypted using two different encryption algorithms. Detailed specifications: Define an abstract class that will be the base class for other two classes. It should have: A...

  • Using C++ Part C: Implement the modified Caesar cipher Objective: The goal of part C is...

    Using C++ Part C: Implement the modified Caesar cipher Objective: The goal of part C is to create a program to encode files and strings using the caesar cipher encoding method. Information about the caesar method can be found at http://www.braingle.com/brainteasers/codes/caesar.php.   Note: the standard caesar cipher uses an offset of 3. We are going to use a user supplied string to calculate an offset. See below for details on how to calculate this offset from this string. First open caesar.cpp...

  • Change the following Shift Cipher program so that it uses OOP(constructor, ect.) import java.util...

    Change the following Shift Cipher program so that it uses OOP(constructor, ect.) import java.util.*; import java.lang.*; /** * * @author STEP */ public class ShiftCipher { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Scanner input = new Scanner(System.in); String plainText; System.out.print("Please enter your string: "); // get message plainText = input.nextLine(); System.out.print("Please enter your shift cipher key: "); // get s int s = input.nextInt(); int...

  • Cryptography, the study of secret writing, has been around for a very long time, from simplistic...

    Cryptography, the study of secret writing, has been around for a very long time, from simplistic techniques to sophisticated mathematical techniques. No matter what the form however, there are some underlying things that must be done – encrypt the message and decrypt the encoded message. One of the earliest and simplest methods ever used to encrypt and decrypt messages is called the Caesar cipher method, used by Julius Caesar during the Gallic war. According to this method, letters of the...

  • Can anyone help me with my C++ assignment on structs, arrays and bubblesort? I can't seem...

    Can anyone help me with my C++ assignment on structs, arrays and bubblesort? I can't seem to get my code to work. The output should have the AVEPPG from highest to lowest (sorted by bubbesort). The output of my code is messed up. Please help me, thanks. Here's the input.txt: Mary 15 10.5 Joseph 32 6.2 Jack 72 8.1 Vince 83 4.2 Elizabeth 41 7.5 The output should be: NAME             UNIFORM#    AVEPPG Mary                   15     10.50 Jack                   72      8.10 Elizabeth              41      7.50 Joseph                 32      6.20 Vince                  83      4.20 ​ My Code: #include <iostream>...

  • /* BEGIN - DO NOT EDIT CODE */ // File: main.cpp #include "LoginAccount.h" #include "RegisteredLoginAccount.h" #include...

    /* BEGIN - DO NOT EDIT CODE */ // File: main.cpp #include "LoginAccount.h" #include "RegisteredLoginAccount.h" #include "GuestLoginAccount.h" #include <iostream> #include <fstream> #include <string> #include <sstream> using namespace std; //prototypes and constants const int ARRAY_SIZE = 20; using number_of_records_t = int; //Function Declarations. void readAccountsFromFile(ifstream& fin, RegisteredLoginAccount registeredAccounts[], number_of_records_t& registeredLength, GuestLoginAccount guestAccounts[], number_of_records_t& guestLength); bool openFileForInput(ifstream& ifs, const string& filename); bool openFileForOutput(ofstream& ofs, const string& filename); void writeAccountsToFile(ofstream& ofs, RegisteredLoginAccount registeredAccounts[], const number_of_records_t registeredLength, GuestLoginAccount guestAccounts[], const number_of_records_t guestLength); void writeAccountToFile(ofstream&...

  • Can someone help me put the string removee the return to an outfile and fix?? prompt: CS 575 LabEx14: no e’s Let the user specify an input file and an output file (text files). Read the input file and...

    Can someone help me put the string removee the return to an outfile and fix?? prompt: CS 575 LabEx14: no e’s Let the user specify an input file and an output file (text files). Read the input file and write the output file; the output file should be the same as the input file, except that it has no e’s. For example, if the input file had the line. Streets meet in the deep. Then the output file would have...

  • You will be writing a simple Java program that implements an ancient form of encryption known...

    You will be writing a simple Java program that implements an ancient form of encryption known as a substitution cipher or a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a "shifted" alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: A B C...

  • Study the VIGENÈRE CIPHER and implemented it with c++ 1.In your program, you should have two...

    Study the VIGENÈRE CIPHER and implemented it with c++ 1.In your program, you should have two functions: encryption and decryption. 2. Use any key you like. (Don't use deceptive in the slides) 3. choose a sentence or a paragraph you like as the plaintext. I have the code I just need the implementation in a different way // C++ code to implement Vigenere Cipher #include<bits/stdc++.h> using namespace std; // This function generates the key in // a cyclic manner until...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT