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

Write a simple program that can encrypt and decrypt a file in the following way.

ID: 3937903 • Letter: W

Question

Write a simple program that can encrypt and decrypt a file in the following way. In the encryption process, your program reads in 11 bits from a file at one time. It then rotates the 11 bits right for two bit positions and output the result to the encrypted file. The decryption process just reverses the process by rotating the 11 bits left two times. During encryption, you may need to pad zero bits to a file which does not end at the boundary of a multiple of 11 and remove the padded bits in the decryption process. In C++ please.

Explanation / Answer

#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;

void encrypt(string fileName, string outputFile){
   std::ifstream infile(fileName);
   ofstream output (outputFile);
   std::string line;
  
   while (std::getline(infile, line))
   {
       std::istringstream iss(line);
       int key;
       if (!(iss >>key)) { break; } // error
       key = key >>2;
       output<<key<<endl;
   }
}
void decrypt(string fileName, string outputFile){
   std::ifstream infile(fileName);
   ofstream output (outputFile);
   std::string line;
  
   while (std::getline(infile, line))
   {
       std::istringstream iss(line);
       int key;
       if (!(iss >>key)) { break; } // error
       key = key <<2;
       output<<key<<endl;
   }
}
int main()
{
encrypt("input.txt","output.txt");
   encrypt("output.txt","input.txt");
return 0;
}

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