-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
53 lines (46 loc) · 1.31 KB
/
main.cpp
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
/**
* CrypTools - GitHub
* Friday, 8 February 2019
* ATBASH Cipher C++ Implementation
* How to use:
* Just write your input text and press enter / return.
* Decrypting and encrypting is the same process.
*/
#include <cstring>
#include <iostream>
#define MAX_INPUT_LENGHT \
2147000 // small values causes bugs for obscure reasons around the end of the
// for-loop
// ASCII VALUES LATIN ALPHABET
#define MINCAP 65
#define MAXCAP 90
#define SPACE 32
#define MINLOW 97
#define MAXLOW 122
using namespace std;
bool crypt(const char* input, char* result);
int main() {
char input[MAX_INPUT_LENGHT], result[MAX_INPUT_LENGHT];
cout << "Input: ";
cin.getline(input, MAX_INPUT_LENGHT);
if (crypt(input, result) == true) {
cout << endl << "Result: " << result << endl;
return 0;
} else {
cout << endl << "Non-alphabet input" << endl;
return 1;
}
}
bool crypt(const char* input, char* result) {
for (unsigned int i = 0; i < strlen(input); ++i) {
if (input[i] == SPACE) {
result[i] = SPACE;
} else if ((input[i] >= MINLOW) && (input[i] <= MAXLOW)) {
result[i] = MAXLOW - (input[i] - 97); //97 - MINLOW
} else if ((input[i] >= MINCAP) && (input[i] <= MAXCAP)) {
result[i] = MAXCAP - (input[i] - 65); //65 - MINCAP
} else
return false;
}
return true;
}