I have a simple application which takes a text and password, generates a text writes it in a file then tries to retrieve it and decrypt it. Before the encryption the 'pad' is generated which is a string generated from the password with the length of the text. The problem comes in when I try to retrieve the text, because no matter how I try I keep retrieving wrong text because it does not match the length of the password.
cout << " !!! DEBUG ONLY. CHANGE MAIN CODE BEFORE RELEASE !!!\n";
string text, password, file;
cout << "Please enter the text you would like encrypted: ";
getline(cin, text);
cout << "Please enter the password for creating the cipher: ";
getline(cin, password);
cout << "Please enter the file path: ";
getline(cin, file);
password = GeneratePad(password, text.size());
string separator = "30436f4a57e831406e8c0ef203923fe3ba9d0ac4TB5Mi4b33A";
ofstream mann(file.c_str(), ios::app);
mann << "\n" << separator << CryptText(text, password);
mann.close();
cout << " !!! DEBUG ONLY. CHANGE MAIN CODE BEFORE RELEASE !!!\n";
ifstream frau(file.c_str(), ios::binary);
string foobar;
bool barfoo = false;
string decrypted;
while (!barfoo)
{
getline(frau, foobar);
if(foobar.find(separator) != string::npos){
decrypted += foobar.substr(separator.length() + 1);
cout << "SUBSTR " << foobar.substr(separator.length() + 1);
barfoo = true; } }
while (getline(frau, foobar))
{
decrypted += foobar;
}
string decrypted2;
cout << " LEN " << decrypted.length() << " !!!!! " << decrypted << endl;
decrypted2 = CryptText(decrypted, password);
cout << decrypted2 << endl;
system("PAUSE");
The things that appear not to be necesarry are purely for debugging (like outputting the raw encrypted text, etc.). Any ideas as to why this happens ?