Alrighty then ive made some changes. Fist of all i descided to use strings instead of arrays after all. Alot easier once i got the hang of it. cin.get works now too since there will never bee excess input, still in the stream. Also, it now handles a file instead of a direct user input. So you have to make a file for the program to work.
The problem now is that the encryption doesnt work properly. I made a file containing the text:
Exclusive-OR (XOR).
Encryption and decryption.
The problem is that the probgram doesnt seem to encrypt all the character. I suppose it has something to do with the key, but how do i work around or fix it?
The program code:
Code:
#include <iostream>
#include <conio.h>
#include <string>
#include <fstream>
using namespace std;
char key[14]="ABCDEFGHIJKLM";
int main()
{
char ch;
ifstream in("c:\\XOR.txt");
string input;
while(1)
{
char ch = in.get();
if(ch == EOF)
break;
input.push_back(ch);
}
cout << endl << "Encypted: \n";
for(int x=0; x<input.size(); x++)
{
input[x] = input[x]^key[x];
cout << input[x];
}
cout << endl;
cout << endl << "Decrypted: \n";
for (int x=0; x<input.size(); x++)
{
input[x] = input[x]^key[x];
cout << input[x];
}
cout << endl << endl;
cout << "Press Enter" << endl;
cout << endl;
cin.get();
return(0);
}