Building a simple program that multiplies the ASCII value of chars in a string by 3 to encrypt and then divide by 3 to decrypt. So far I got the encryption part down but whenever I enter what the encryption gave and try to decrypt it doesn't work. I think it has something to do with the buffer stream but I could be wrong if anyone could help.
#include<iostream>
using namespace std;
int main()
{
string message;
int charValue;
int counter;
int encrypt;
char choice;
char quit = 'N';
while (quit == 'N')
{
cout << "Enter E to encrypt or D to Decrypt\n";
cin >> choice;
toupper(choice);
cout << "Enter text no spaces: ";
cin >> message;
int messagelen = message.length();
string stringArray[255];
if (choice == 'E')
{
for (counter = 0; counter < messagelen; counter++) //*3 to ascii val
{
stringArray[counter] = message[counter] * 3;
}
for (counter = 0; counter < messagelen; counter++)
{
cout << stringArray[counter];
}
}
else
{
for (counter = 0; counter < messagelen; counter++) // divide 3 to ascii val
{
stringArray[counter] = message[counter] / 3;
}
for (counter = 0; counter < messagelen; counter++)
{
cout << stringArray[counter];
}
}
cout << "\nY to go again N to quit";
cin >> quit;
}
return 0;
}