I want to XOR all the ASCII values in a .txt file with all the ASCII values up to 256. My input .txt file contains the ASCII values in hex format. So for instance, my input file has "49 f3 54 f3 5f f3 47 f4 43 e8 49 e9" and I want to XOR each value with 0x00 followed by 0x01, 0x02, 0x03 and so on and print the result in a new line for every hex value. I have written the following the code in C++ but it always prints the original content.
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int main() {
vector <char> decrypt;
char ch;
int index;
int key = 0;
ifstream infile;
ofstream outfile;
infile.open("prob3.txt");
outfile.open("results3_p1.txt");
if(!infile)
{
cout << "Error opening input file" << endl;
return 0;
}
for (int a = 0; a < 256; a++)
{
while(infile >> hex >> index)
{
ch = index ^ key;
decrypt.push_back(ch);
}
for (int i=0; i<decrypt.size(); i++) // Print the results
{
outfile << decrypt[i];
}
outfile << endl;
}
return 0;
}
I tried to clear the vector using "decrypt.clear()" but that does not print anything after the first iteration. I am not sure which part of my code in incorrect.
The output from my code -
Aucun commentaire:
Enregistrer un commentaire