Hi everyone.
Recently I have been working on an XOR encryptor/decryptor. I have looked at tutorials to get ideas. Now, I have created my encryptor/decryptor and I have absolutely messed it up i think, because the output is not right. What I am trying to do here is:
- Creating a string for the user to input the unencrypted text.
- Create a for loop.
- Get the length of the string by using string.length()
- Using Xor operator to "XOR" the string with the encryption key i made.
- Then create another string for the user to input the encrypted text.
- Use the same keys to "XOR" with the encrypted text to obtain
I will add a switch statement later.
Here is the code I've made, i do not know what to put in after
"^ encryption_key[]" in the for loop. I know what the [] is for though.
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string decrypt_string;
string input_string;
char encryption_key[8] = "ABCDEFG";
cout << "Please enter the text you would like to encrypt below:"<<endl<<endl;
getline (cin, input_string);
cout<<endl<<endl<<"Below is the encrypted text:"<<endl;
for(int i=0; i<=input_string.length(); i++) {
input_string[i]=input_string[i] ^ encryption_key[];
// I do not know what to put in for the [] after encryption_key.
cout<<input_string[i];
}
cout<<endl<<endl;
cin.get();
cout << "Please enter the text you would like to decrypt below:"<<endl<<endl;
getline (cin, decrypt_string);
decrypt_string.length();
cout<<endl<<endl<<"Below is the decrypted text:"<<endl;
for(int y=0; y<=decrypt_string.length(); y++ ) {
decrypt_string[y]=decrypt_string[y] ^ encryption_key[];
cout<<decrypt_string[y];
}
cout<<endl<<endl;
system("PAUSE");
return 0;
}
Thanks.