I'm trying to encrypt a text message into integers and decrypt from integers to a text message. First, the program asks the user whether they want to encrypt or decrypt. If the user selects encrypt, they are asked to enter a text message such as "A large dog!". The program then outputs an integer of random numbers between 1 and 254, such as "200 169 229 232 251 238 236 169 237 230 238 168." The opposite goes for if the user selects decrypt. This is what I have so far:
CODE
#include<iostream>
#include<cstring>
using namespace std;
void encrypt(char []);
int main ()
{
char textstring[100];
char numstring[100];
char choice;
cout << "Enter choice: (E)ncryption, (D)ecrpytion" << endl;
cin >> choice;
if (choice == 'E')
{
cout << "Please enter a line of text: " << endl;
cin.getline(textstring,100);
while(textstring != '\0')
{
encrypt(textstring);
}
}
else
{
cout << "Please enter the encrypted values: " << endl;
cin.getline(numstring,100);
}
return 0;
}
void encrypt(char str[])
{
int len = strlen(str);
for(int n=0; n<len; n++)
{
if(isspace(str[n]))
{
cout << "100 ";
}
}
}
I am unsure as to what I should do now. I was told the the exclusive OR (^) operator comes in handy and was even given an example:
CODE
const int KEY = 137;
char letter = ‘A’;
int code;
char newletter;
code = letter ^ KEY;
cout << code is: “ << code << endl;
newletter = code ^ KEY;
cout << original char is: “ << newletter << endl;
However, I don't know where to put this and how to expand so that ever letter is like this without doing the long way.
Please help!!