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

C++ code I need decryption ( must loop through the encrypted file and again, xor

ID: 3890497 • Letter: C

Question

C++ code I need decryption ( must loop through the encrypted file and again, xor every byte with a one ) ?? Basically the opposite of if the code below ??
so this is picture below is encrypted part ( it loops through the input file and xor every byte with a one.) ..il AT&T; #include "Main.h" int encryptData(char *data, int d 6:08 PM ataLength) asm ( mov ebx, 0 mov ecx, data srt loop: cmp dataLength, ebx jmp end_loop mov al ,byte ptr[ecx] xor al, 1 mov byte ptr[ecx],al jmp srt loop end_loop: return 0

Explanation / Answer

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

void decrypt(const std::string& filename){

streampos size;
char * memblock;
string in;
string out;

in = filename;
out = filename + "-decrypt";

ifstream file (in.c_str(), ios::in|ios::binary);
ofstream ofile (out.c_str(), ios::out|ios::binary);

if (file)
{
    file.seekg (0, ios::end);
    size = file.tellg();
    memblock = new char [size];
    file.seekg (0, ios::beg);
    file.read (memblock, size);
    file.close();
   
   
   
    for (int i = 0; i<size; i++){
        memblock[i] = memblock[i] ^ 1;
    }
     
    for (int i = 0; i<size; i++){
        ofile.write(&memblock[i],1);
    }
       
    ofile.close();  

    delete[] memblock;
   }
}

int main () {
string filename;

cout << "Enter file name :" << endl;
cin >> filename;
decrypt(filename);
}

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