I want to encrypt the string of password entered by user, and then print it on screen. Also recover the original password and then print it on screen too. But XOR operator is not working with strings. How can I manipulate it?
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
string pass;
string enc="akdhigfohre";
string x;
cout<<"Enter new password: ";
cin>>pass;
cout<<"\n\nYour New Password is:" << pass<<endl;
x=pass^enc;
cout<<"\n\nEncrypted Version: "<<x;
x=x^enc;
cout<<"\n\nRecovred Password: "<<x;
system("pause");
}
Just another try on the code base of the question ,
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
string pass;
string enc="akdhigfohre";
string x = "";
string y = "";
cout<<"Enter new password: ";
cin>>pass;
cout<<"\n\nYour New Password is:" << pass<<endl;
for(size_t i = 0; i < pass.size(); ++i){
x += pass.at(i)^enc.at(i%enc.size());
}
cout<<"\n\nEncrypted Version: "<<x;
for(size_t i = 0; i < x.size(); ++i){
y += x.at(i)^enc.at(i%enc.size());
}
cout<<"\n\nRecovred Password: "<<y;
system("pause");
}