-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLock.cpp
More file actions
58 lines (56 loc) · 1.48 KB
/
Lock.cpp
File metadata and controls
58 lines (56 loc) · 1.48 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
57
58
//
// Created by berka on 14.05.2022.
//
#include "Lock.hpp"
namespace s25786 {
auto Lock::encrypt (std::string str) -> std::string {
auto key = 3;
for(auto i = 0; str[i] != '\0'; ++i) {
auto ch = str[i];
if (ch >= 'a' && ch <= 'z') {
ch = ch + key;
if (ch > 'z') {
ch = ch - 'z' + 'a' - 1;
}
str[i] = ch;
}
else if (ch >= 'A' && ch <= 'Z') {
ch = ch + key;
if(ch > 'Z') {
ch = ch - 'Z' + 'A' -1;
}
str[i] = ch;
}
else {
ch = ch + key;
str[i] = ch;
}
}
return str;
}
auto Lock::decrypt (std::string str) -> std::string {
auto key = 3;
for (auto i = 0; str[i] != '\0'; ++i) {
auto ch = str[i];
if(ch >= 'a' && ch <= 'z') {
ch = ch - key;
if(ch < 'a') {
ch = ch + 'z' - 'a' + 1;
}
str[i] = ch;
}
else if(ch >= 'A' && ch <= 'Z') {
ch = ch - key;
if(ch > 'a') {
ch = ch + 'Z' - 'A' + 1;
}
str[i] = ch;
}
else {
ch = ch - key;
str[i] = ch;
}
}
return str;
}
} // s25786