-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
56 lines (45 loc) · 2.86 KB
/
Copy pathmain.cpp
File metadata and controls
56 lines (45 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
char encrypt(char stringSymbol, int key){ // Функция шифрования
return char ( int(stringSymbol) + key );
}
char decrypt(char stringSymbol, int key){ // Функция дешифрования
return char ( int(stringSymbol) - key );
}
int main() {
std::string inputString; // Входная строка
std::string outputString; // Выходная строка
int key, mode; // Переменные управления состоянием
std::cout << "Hello, please select one of the following operating modes !" << std::endl
<< "1. Encrypt the string" << std::endl
<< "2. Decrypt the string" << std::endl
<< "Enter mode number: ";
std::cin >> mode; // Ввод пользователем выбранного режима работы
switch (mode) { // Управление потоком выполнения
case 1:
std::cout << std::endl << "You're selected encryption mode." << std::endl
<< "Please enter your unencrypted string and key (a count of offset symbols)" << std::endl
<< "Separating the string and key with a space" << std::endl << "Enter here: ";
std::cin >> inputString >> key; // Ввод строки нешифрованного сообщения и ключа шифрования
for (int i = 0; i < inputString.length(); i++){ // Процесс посимвольного шифрования сообщения
outputString += encrypt(inputString[i], key);
}
std::cout << "You're encrypted string: " << outputString << std::endl // Вывод шифрованной строки
<< " You're decryption key: " << key << std::endl;
break;
case 2:
std::cout << std::endl << "You're selected decryption mode." << std::endl
<< "Please enter your encrypted string and key" << std::endl
<< "Separating the string and key with a space" << std::endl
<< "Enter here: ";
std::cin >> inputString >> key; // Ввод строки шифрованного сообщения и ключа дешифровки
for (int i = 0; i < inputString.length(); i++){ // Процесс посимвольного дешифрования сообщения
outputString += decrypt(inputString[i], key);
}
std::cout << "You're decrypted string: " << outputString << std::endl; // Вывод дешифрованной строки
break;
default: // Отработка ошибки ввода
std::cout << "You're entered wrong number of mode !";
break;
}
return 0;
}