Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.cpp
More file actions
Latest commit
53 lines (46 loc) · 1.31 KB
/
Copy pathmain.cpp
File metadata and controls
53 lines (46 loc) · 1.31 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
/**
* 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>
#defineMAX_INPUT_LENGHT \
2147000// small values causes bugs for obscure reasons around the end of the
// for-loop
// ASCII VALUES LATIN ALPHABET
#defineMINCAP65
#defineMAXCAP90
#defineSPACE32
#defineMINLOW97
#defineMAXLOW122
usingnamespacestd;
boolcrypt(constchar* input, char* result);
intmain() {
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;
return0;
} else {
cout << endl << "Non-alphabet input" << endl;
return1;
}
}
boolcrypt(constchar* input, char* result) {
for (unsignedint i = 0; i < strlen(input); ++i) {
if (input[i] == SPACE) {
result[i] = SPACE;
} elseif ((input[i] >= MINLOW) && (input[i] <= MAXLOW)) {
result[i] = MAXLOW - (input[i] - 97); //97 - MINLOW
} elseif ((input[i] >= MINCAP) && (input[i] <= MAXCAP)) {
result[i] = MAXCAP - (input[i] - 65); //65 - MINCAP
} else
returnfalse;
}
returntrue;
}