-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlevel1.cpp
More file actions
29 lines (27 loc) · 715 Bytes
/
level1.cpp
File metadata and controls
29 lines (27 loc) · 715 Bytes
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
#include <iostream>
#include <string>
using namespace std;
string decode(string text, int key) {
string result = "";
string charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
int n = charset.length();
for (char c : text) {
int pos = charset.find(c);
if(isalnum(c)){
int newPos = (n + pos - key) % n;
result += charset[newPos];
}
else{
result += c;
}
}
return result;
}
int main() {
string s = "YZH(878GBC 8BFC87 8C7999 F8AFB ADA8GG 8GGCC7 A7F9EG 8BFDAB)";
for (int key = 0; key < 36; key++) {
string decodedText = decode(s, key);
cout << decodedText << endl;
}
return 0;
}