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

we are going to be creating a basic encryption/decryption function. The principl

ID: 3675956 • Letter: W

Question

we are going to be creating a basic encryption/decryption function. The principle function we are writing will call an encrypt function and/or a decrypt function. Normally, I wouldn't spec the additional functions for you to write but for this lab I'm listing at least 3 functions you need to write. Our encryption is going to be basic. If a letter is simply going to be replaced with a different letter from the alphabet. Use this scheme when encrypting or decrypting: a == z b == y c == x d == w e == v f == u g == t h == s i == r j == q k == p l == o m == n

Requirements

You must write your method signatures in a file called: encrypt.h

You must write the principle function with signature: void encryptDecrypt( string inputfile, string outputfile );

this is in c++

Explanation / Answer

Here is the code

encrypt.h

#ifndef ENCRYPT

#include <iostream>
using namespace std;

void encryptDecrypt( string inputfile, string outputfile);
#endif

mainfile.cpp

#include <iostream>
#include <fstream>
#include <string>
#include<encrypt.h>

using namespace std;

void encryptDecrypt(string inputfile, string outputfile)
{
  
   //the standard streams doesn't accept a standard string, only c-string! so use c_str()
   ifstream infile(inputfile.c_str());
   ofstream outfile (outputfile.c_str());

if (!infile)
{
       cout <<"File not found";
       exit(EXIT_FAILURE);
   }
char cur = '';
char newc;
cout << "Encryption Started....."<<endl;

while (infile.get(cur))
   {
       switch(cur)
       {
           case 'a':
           newc='z';
          break;
          case 'b':
           newc='y';
          break;
          case 'c':
           newc='x';
          break;
          case 'd':
           newc='w';
          break;
          case 'e':
           newc='v';
          break;
          case 'f':
           newc='u';
          break;
          case 'g':
           newc='t';
          break;
          case 'h':
           newc='s';
          break;
          case 'i':
           newc='r';
          break;
          case 'j':
           newc='q';
          break;
          case 'k':
           newc='p';
          break;
          case 'l':
           newc='o';
          break;
          case 'm':
           newc='n';
          break;
         
          case 'z':
           newc='a';
          break;
          case 'y':
           newc='b';
          break;
          case 'x':
           newc='c';
          break;
          case 'w':
           newc='d';
          break;
          case 'v':
           newc='e';
          break;
          case 'u':
           newc='f';
          break;
          case 't':
           newc='g';
          break;
          case 's':
           newc='h';
          break;
          case 'r':
           newc='i';
          break;
          case 'q':
           newc='j';
          break;
          case 'p':
           newc='k';
          break;
          case 'o':
           newc='l';
          break;
          case 'n':
           newc='m';
          break;
         
          default:
          newc=cur;
       }
      
       outfile.put(newc);

  
}
cout << "Encryption Complete. Please check the output file "<<endl;
}

int main() {

   string inputfile, outputfile;
   inputfile="input.txt";
   outputfile="outfile.txt";
   char *filename="paragraph.txt";
  
   encryptDecrypt(inputfile,outputfile);


}