-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolybius.cpp
More file actions
56 lines (45 loc) · 1.42 KB
/
Polybius.cpp
File metadata and controls
56 lines (45 loc) · 1.42 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>
#include <string>
#include <Windows.h>
constexpr auto N = 6;
const char POLYBIUS[N][N] = {
{ '�', '�', '�', '�', '�', '�'},
{ '�', '�', '�', '�', '�', '�'},
{ '�', '�', '�', '�', '�', '�'},
{ '�', '�', '�', '�', '�', '�'},
{ '�', '�', '�', '�', '�', '�'},
{ '�', '�', '�', ' ', ',', '.'}
};
char encrypt(const char c);
char decrypt(const char c);
int main() {
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
std::string c, _c;
int i;
std::cout << "������� ������:\n";
std::getline(std::cin, c);
std::cout << "\n----------�������������----------" << std::endl;
for (i = 0; i < c.size(); ++i)
_c += encrypt(c[i]);
std::cout << _c << std::endl;
std::cout << "\n----------��������������---------" << std::endl;
for (i = 0; i < _c.size(); ++i)
std::cout << decrypt(_c[i]);
std::cout << std::endl;
return 0;
}
char encrypt(const char c) {
int i, j;
for (i = 0; i < N; ++i)
for (j = 0; j < N; ++j)
if (POLYBIUS[i][j] == c)
return POLYBIUS[(i + 1) % N][j];
}
char decrypt(const char c) {
int i, j;
for (i = 0; i < N; ++i)
for (j = 0; j < N; ++j)
if (POLYBIUS[i][j] == c)
return POLYBIUS[(i + (N - 1)) % N][j];
}