The Program should print the expected messages as expected but its not printing.
Plain Text message: Hello! how are you?
Expected encrypted message: Glqqv! bvc Rfl avm?
The program is printing: Glqqv!bvcRflavm
White spaces are totally ignored. How to fix it?
The Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string alphabet {"!A2BCDEFGHIJ@KLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"};
string key {"!X2ZNLWEBGJHQDYVTK2F#UOMPCIASRxznlwebgjhqdyvtkfuompciasr"};
string secret_message{};
string encrypted_message{};
cout << "Enter your secret message: ";
getline(cin, secret_message);
cout << "'nEncrypting message.... ";
for (char c: secret_message)
{
float position = alphabet.find(c);
if(position != string::npos)
{
char new_char {key.at(position)};
encrypted_message += new_char;
}
}
cout << "\n Encrypted message is: "<< encrypted_message << '\n';
cout << "\n\n" << '\n';
return 0;
}