-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecode.cpp
More file actions
51 lines (45 loc) · 1.08 KB
/
decode.cpp
File metadata and controls
51 lines (45 loc) · 1.08 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
q#include "permutation.h"
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
typedef long long int64;
using namespace std;
int main() {
fstream f1("encoded.txt", fstream::in);
fstream f2("decoder.txt", fstream::in);
fstream f3("poetry.txt", fstream::in);
freopen("decoded.txt", "wb", stdout);
string str;
string s;
while (getline(f2, s))
str += s;
vector<int> a = get_permutation(str);
a = get_inv_permutation(a);
map<string, int> b;
for (int i = 0; i < 256; ++i) {
getline(f3, s);
b[s] = i;
}
int i = 0;
while (getline(f1, s)) {
int pos = (b[s]) % 256;
pos = a[pos];
pos -= i;
pos %= 256;
if (pos < 0)
pos += 256;
cout << (char)pos;
++i;
}
return 0;
}