#include <iostream>
#include <string>
#include <cmath>
Go to the source code of this file.
◆ check_within_a_z()
bool check_within_a_z |
( |
char | test | ) |
|
Definition at line 148 of file 1.cpp.
148 {
149 if (((int)test >= 65) && ((int)test <= 90) || ((int)test >= 97) && ((int)test <= 122)){
150 return true;
151 }
152 else{
153 return false;
154 }
155}
Referenced by main().
◆ convert_position_alphabet()
void convert_position_alphabet |
( |
char & | letter | ) |
|
Definition at line 140 of file 1.cpp.
140 {
141 if ((int)letter >= 97){
142
143 letter = ((int)letter - 32);
144 }
145 letter = (int)letter - 65;
146}
Referenced by decryption(), and encryption().
◆ decryption()
char decryption |
( |
int | key1, |
|
|
int | key2, |
|
|
char | letter ) |
Definition at line 78 of file 1.cpp.
78 {
80
81
82
83
84
85
86
87
88
89
90 if (
gcd(key1, 26) == 1){
91
94 int y = mmi_of_a*(letter-
key2) % 26;
95 if (y < 0){
96 y += 26;
97 }
98 letter = y;
100 letter = letter + 97;
101 }
102 else{
103 letter = letter + 65;
104 }
105 return letter;
106 }
107 else{
108
109
110
111
112
113 return '!';
115 for (int i = 65+change_case; i < 91+change_case; i++){
116 if (
encryption(key1, key2, (
char)i) == letter){
117 return i;
118 }
119 }
120 }
121 return letter;
122}
char encryption(int key1, int key2, char letter)
void convert_position_alphabet(char &letter)
int find_mmi(int a, int mod_value)
string upper_case(string str)
References convert_position_alphabet(), encryption(), find_mmi(), gcd(), and upper_case().
Referenced by main().
◆ encryption()
char encryption |
( |
int | key1, |
|
|
int | key2, |
|
|
char | letter ) |
◆ find_mmi()
int find_mmi |
( |
int | a, |
|
|
int | mod_value ) |
Definition at line 124 of file 1.cpp.
124 {
125
126
127
128 for (int i = 1; i <= mod_value; i++){
129 if (abs(a*i % mod_value) == 1){
130 return i;
131 }
132 }
133 return -1;
134
135
136
137
138}
Referenced by decryption().
◆ gcd()
Definition at line 157 of file 1.cpp.
157 {
158 while(a != b){
159 if (a>b){
161 }
162 else if (a<b){
164 }
165 else{
166 break;
167 }
168 }
170}
Referenced by decryption(), lcm(), and main().
◆ main()
Definition at line 19 of file 1.cpp.
19 {
20 char mode;
22 string input;
24 char character;
25 while(true){
26 cin >> character;
27 input.push_back(character);
28 if (character == '!'){
29 break;
30 }
31 else{
32 input.push_back(' ');
33 }
34 }
35 switch(mode){
36 case 'e':
37 for (int i=0; i < input.length(); i++){
40 }
41 else{
42 cout << input[i];
43 }
44 }
45 cout << endl;
46 break;
47 case 'd':
48 for (int i=0; i < input.length(); i++){
51 }
52 else{
53 cout << input[i];
54 }
55 }
56 cout << endl;
57 break;
58 }
59 return 0;
60}
char decryption(int key1, int key2, char letter)
bool check_within_a_z(char test)
References check_within_a_z(), decryption(), and encryption().