Encryption code not working
Hello. Can anyone here tell me why this code
won't work (you can run it to see what I mean)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <include.h>
#include <encrypt.h>
int main()
{
char a;
string data;
ifstream dataFile;
dataFile.open("text.dat");
dataFile >> data;
encrypt(data, "test");
cout << "Encrypted data: " << data << "\n";
cout << "Decrypt yes data? (y/n): ";
cin >> a;
if(a == 'y')
{
decrypt(data, "test");
cout << "Decrypted data: " << data << "\n";
}
return 0;
}
| |
the encrypt.h header is the encryption function from here:
http://www.cplusplus.com/forum/windows/128374/
include.h is a custom header which includes:
iostream, string, fstream and maybe others I forgot.
EDIT: I had the input file's name wrong. (text.dat instead of text.txt)... Sorry.
Last edited on
Does this work?
1 2 3
|
encrypt(data, "test");
decrypt(data, "test");
cout << "Decrypted data: " << data << "\n";
| |
Is it just failing to print the intermediate step, but the final result works?
I figured out what was wrong, I should have done:
1 2
|
data = encrypt(data, "test); // "data =" added
cout << data;
| |
This step can be avoided by changing the first
parameter of encrypt() to
string &
and, also, I had the input file name wrong.
I had it like this:
"text.dat"
instead of
"text.txt"
Last edited on
Topic archived. No new replies allowed.