Encrypted secrete messages in C++
How to send Encrypted secrete messages in C++ and Decrypt the same message?
#include <iostream>
#include<string>
using namespace std;
int main()
{
string message;
int i,a,word;
string letters ={"ABCDEFGHIKLMNOPQRSTVXYZabcdefghijklmnopqrstuvwxyz"};
string key= {"sub£rmatoglyphicAXPYRIQW\CMSWBFG@1029384756!&()="};
cout<<"Enter the message: ";
getline(cin,message);
string encrypted_message;
string decrypted;
for(char c:message){
size_t position=letters.find(c);
if (position !=string::npos)
{
char new_char = key.at(position);
encrypted_message+=new_char;
}
else
{
encrypted_message+=c;
}
for(char c:key)
size_t position=key.find(c);
if(position!=string::npos)
{
char new_char=letters.at(position);
decrypted +=new_char;
}
else
{
decrypted+=c;
}
}
cout<<"\nEncrypted message: "<<encrypted_message<<endl;
cout<<"\nDecrypted message: "<<decrypted<<endl;
cout<<endl;
return 0;
}
Comments
Post a Comment