#include <iostream> #include <string> #include <windows.h> using namespace std; void…
- User
#include #include #include <windows.h>
using namespace std;
void FirstOrSecond(bool isEncryption) { int a; string s1; char s_eng_small[] = "abcdefghijklmnopqrstuvwxyz"; char s_eng_big[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char s_rus_small[] = "абвгдеёжзийклмнопрстуфхцчшщъыьэюя"; char s_rus_big[] = "АБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ";
cout << "Напишите текст: \n"; cin.get(); getline(cin, s1); cout << "Напишите шаг (введите отрицательное число для расшифровки): \n"; cin >> a; for (int i = 0; i < s1.size(); i++) { bool found = false; for (int j = 0; j < 26; j++) { if (s1[i] == s_eng_small[j]) { int adjusted_a = ((isEncryption ? a : -a) % 26 + 26) % 26; // Добавлено 26, чтобы избежать отрицательных индексов, s1[i] = s_eng_small[(j + adjusted_a) % 26]; found = true; break; } else if (s1[i] == s_eng_big[j]) { int adjusted_a = ((isEncryption ? a : -a) % 26 + 26) % 26; s1[i] = s_eng_big[(j + adjusted_a) % 26];// found = true; break; } } if (!found) { for (int j = 0; j < 33; j++) { if (s1[i] == s_rus_small[j]) { int adjusted_a = ((isEncryption ? a : -a) % 33 + 33) % 33; s1[i] = s_rus_small[(j + adjusted_a) % 33]; found = true; break; } else if (s1[i] == s_rus_big[j]) { int adjusted_a = ((isEncryption ? a : -a) % 33 + 33) % 33; s1[i] = s_rus_big[(j + adjusted_a) % 33]; found = true; break; } } } cout << s1[i];// необработанные символы }}
int main() { setlocale(LC_ALL, "Russian"); SetConsoleCP(1251); SetConsoleOutputCP(1251);
int r; cout << "Выбор режима: Шифрование(1), Дешифрование(2)."; cin >> r; if (r == 1) { FirstOrSecond(true); } else if (r == 2) { FirstOrSecond(false); } else { cout << "Неправильно введен режим. Выберите правильный режим и попробуйте снова.\n"; } return 0;} Напиши комментарии к всей программер
- Assistant