Needed decryption!!!! ? must loop through the encrypted file and again xor every
ID: 3890717 • Letter: N
Question
Needed decryption!!!! ? must loop through the encrypted file and again xor every byte with a one). Picture below did decryption data outline.
/I EncryptData.cpp // This file uses the input data and key information to encrypt the input data #include "Main"h" /I code to encrypt the data as specified by the project assignment int encryptData(chardata, int dataLength) int resulti-0; gdebug 1 = 0; gdebug2-0 // a couple of global variables // also can have a breakpoint i# // You can not declare any local variables in C, but should use resulti to indic /I Set up the stack frame and assign variables in assembly if you need to do so /I access the parameters BEFORE setting up your own stack frame // Also, you cannot use a lot of global variables - work with registers asm // you will need to reference some of these global variables // (gptrPasswordHash or gPasswordHash), (gptrKey or gkey), gNumRounds // simple example that xors 2nd byte of data with 14th byte in the key 1 lea esi,gkey mov esi,gptrkey; // put the ADDRESS of gkey into // put the ADDRESS of gkey into ca esi,gPasswordHash /I put ADDRESS of gPasswordHash mov esi,gptrPasswordHash // put ADDRESS of gPasswordHash into es mov al,byte ptr esi] mov al,byte ptr esit4] mov ebx,2 mov al,byte ptr esi+ebx] mov al,byte ptr esitebx 2] /I get first byte of pas // get 5th byte of pass /I get 3rd byte of pass /I get 5th byte of passt mov ax,word ptr esi+ebx 2) mov eax, dword ptr [esitebx 2 // gets 5th and 6th byte // gets 4 bytes, as in: unsigne mov al,byte ptr [gkey+ebx] // get's 3rd byte of gk mov al,byte ptr gptrKey+ebx /I THIS IS INCORRECT will add /I access 14th byte in mov al,byte ptr esit0xdl; mov edi,data xor byte ptr [edi+i],al /I Put ADDRESS of first data el /I Exclusive-or the 2nd byte of data wit NOTE: Keyfile // capital "B" return resulti I encryptData
Explanation / Answer
DECRYPTED CODE
#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);
}
Main concern of the program to read a given file that as you given encrypted code the decrypted code as above
THANK YOU
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.