Write a simple program that can encrypt and decrypt a file i

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.

Solution

#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;
}

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 tim

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site