Answer the question
In order to leave comments, you need to log in
How can I fix the program so that the original message is equal to the decrypted one?
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
using namespace std;
int main() {
setlocale(LC_ALL, "rus");
char msg[] = "Привет мир!";
unsigned char key = 84;
int N = strlen(msg);
cout << N << endl;
for (int i = 0; i < N; ++i) {
msg[i] ^= key;
msg[i] = ((msg[i] >> 2) | (msg[i] << 6));
}
for (int i = 0; i < N; ++i) cout << msg[i];
cout << endl;
for (int i = 0; i < N; ++i) {
msg[i] = ((msg[i] >> 6) | (msg[i] << 2));
msg[i] ^= key;
}
for (int i = 0; i < N; ++i) cout << msg[i];
cout << endl;
return 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question