У меня проблема с домашним заданием. https://gyazo.com/443dd9aee7b2ebe24a3a781d97150a70. В конце я пытаюсь расшифровать зашифрованный текст, но он просто показывает пароль, а не сообщение! Пожалуйста помоги! Это должно произойти очень скоро!
Я попытался включить уравнение xor gate, но оно не сработало.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string m;
cout << "Please enter your message" << endl;
getline(cin, m);
cout << " " << endl;
char p;
cout << "Please enter a one-character password" << endl;
cin >> p;
cout << " " << endl;
cout << "Encrypting..." << endl;
cout << " " << endl;
string c;
for (int i = 0; i<m.length(); i++) {
c += m[i]^p;
}
cout << "Your ciphertext is " << endl;
cout << c << endl;
cout << " " << endl;
cout << "Decrypting..." << endl;
string m2;
for (int i = 0; i < c.length(); i++) {
m2 = c[i+1]^p;
}
cout << "Your message is" << endl;
cout << m2 << endl;
return 0;
}
В конце мне действительно нужно, чтобы м2 отображалось как сообщение, а не пароль.