My enscription program enscripts the words in a text file, but when I descript it is all mixed up eg.
Origanal text: Name: Master
Surname: Hacker
Age: 1101
Enscripted text: 6BX5
6BX5
+
BX0
6BX5
+
BX0
9BXIIHI
Descripted text:
Name: MasteName: MasteName: MasteName: MasteName: MasteSuName: MasteName: MasteSuname: HackeName: MasteName: MasteSuname: HackeName: MasteName: MasteName: MasteSuname: HackeName: MasteSuName: MasteName: MasteSuname: HackeName: MasteSuname: HackeName: MasteName: MasteSuname: HackeName: MasteSuname: HackeAge: 1101
I dont know why it does that. If any of you could please help me with my code and help me fix it so that it can enscript and descript the text.
Here is the code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string line;
char key = 'x';
string enscripted;
char inFile[100];
char outFile[100];
cout<<"File for input: ";
cin.getline(inFile, 99);
cout<<"File for output: ";
cin.getline(outFile, 99);
ifstream file1(inFile);
ofstream file2;
file2.open(outFile, ios::app);
if(file1.is_open())
{
while(file1.good())
{
getline(file1, line);
for(int i = 0; i < line.size(); i++)
{
enscripted += line[i] ^ (int(key)+i) % 1101;
}
file2<<enscripted;
}
}
file2.close();
return 0;
}
:)