|
Hey. I recently created a simple file encryption program that opens a file, reads the contents, encrypts the contents using a simple XOR process, and rewrites the file. Ive posted the source code below with a changed encryption key as reference.
I have encountered two problems. The program will not allow me to assign a value contained in a variable to a character array, so the line (char string[50] = line;) becomes invalid. I have not been able to figure a way around this problem as yet. I have created classes, tried using different types of arrays, and some other stuff, with no success, so I modifyed the source code to allow for manual encryption. Was wondering if anyone could help me figure a way to assign the value containted in (string line) to (char string[50]) and still have a working encryption? There is probably a really basic solution to this problem that i just keep overlooking.
My second problem is that I just haven't been able to figure out a way to count ONLY the number of spaces in a text file, because this algorithm does not encrypt spaces. lol need help with that too.
#include <cstdlib>
#include <iostream>
#include <stdlib.h>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
int main(int argc, char *argv[])
{
long begin, end;
string line;
ifstream myfile ("/forum/file.txt");
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
else cout << "Unable to open file";
myfile.open ("/forum/file.txt");
begin = myfile.tellg();
myfile.seekg (0, ios::end);
end = myfile.tellg();
myfile.close();
char string[50];
char key[129] = "ZaQ12wSXCde34RFVBGt56YHNMJu78IkLO9oP09OlKI87UjMNHY65tGbVFR43edCXSW21QAZAQ12WSXCDE34RFvbGT56YhNmJU78IKLO90P09OLKI87UJMNhY65TGBVFr";
ofstream newfile ("/forum/file.txt");
if (newfile.is_open())
{
for (int x=0; x<((end-begin)-5); x++)
{
cin >> string[50];
string[x]=string[50]^key[129];
cout << string[x];
newfile << string[x];
}
newfile.close();
}
cout << endl << "\nFile encrypted" << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
|
|
|
|
|
|
|
|