//Declarations
int main ()
{
string text;
char Key = 'x';
getline (cin,text);
ofstream File ("File.txt");
File << "The encrypted text is - " << text;
File.close();
string file;
ifstream File1 ("File.txt");
while (File1.good())
{
getline (File1,file);
}
File1.close();
ofstream EnFile ("EncryptedFile.txt");
for (int x = 0; x < file.size();x++)
{
file[x] ^= Key;
EnFile << file[x];
}
EnFile.close();
string decrypt;
ifstream DeFile ("EncryptedFile.txt");
if (DeFile.is_open())
{
while(!DeFile.eof()){
getline (DeFile,decrypt);
for (int x = 0; x < file.size();x++)
{
decrypt[x] ^= Key;
cout << decrypt[x];
}}
}
else
cout << "Unable to open file \n\n";
//Termiantion
Can someone please help me with this problem??
EDIT: The Decryption part gives [output]The enc[/Output], and then the error occurs. And yes, I saw the previous post, but I haven't even come to classes yet, So I think this is better for basicrogramming.
Thanks! Now i works.
But is there any way to make it work for the string literals?
I thought that by putting it in a file, then, retrieving it into another string, and then doing the encryption to the single string would work!