-
Notifications
You must be signed in to change notification settings - Fork 0
/
L10-1.cpp
86 lines (68 loc) · 1.44 KB
/
L10-1.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <bits/stdc++.h>
#include "aeslibc.h"
#include "aeslibc.c"
using namespace std;
typedef long long ll;
#define PUB push_back
#define fi first
#define se second
void enkripsi(HexStr &p, HexStr &c, HexStr &k){
Block pt, ck, ct;
hexstr2block ( p, pt );
hexstr2block ( k, ck );
encrypt ( pt, ck, ct );
block2hexstr ( ct, c );
}
void dekripsi(HexStr &p, HexStr &c, HexStr &k){
Block pt, ck, ct;
hexstr2block ( k, ck );
hexstr2block ( c, ct );
decrypt ( ct, ck, pt );
block2hexstr ( pt, p );
}
int s;
string hexa = "0123456789ABCDEF";
HexStr k1, k2, awal, akhir;
map<string, string> stt;
bool ketemu = 0;
void BF(int pos, int id){
if(pos == s){
if(id == 0){
HexStr c;
enkripsi(awal, c, k1);
if(stt.count(c) == 0) stt.insert({c, k1});
}else{
HexStr p;
dekripsi(p, akhir, k2);
if(stt.count(p) > 0){
ketemu = 1;
cout << stt[p] << endl;
cout << k2 << endl;
}
}
return;
}
for(int i=0;i<16;i++){
HexStr p, c;
if(id == 0){
k1[pos] = hexa[i];
}else if(id == 1){
k2[pos] = hexa[i];
}
if(!ketemu) BF(pos+1, id);
}
}
int main(){
for(int i=1;i<=10;i++){
freopen(("input/ioi-2001-double-crypt_"+to_string(i)+".in").c_str(), "r", stdin);
freopen(("output/ioi-2001-double-crypt_"+to_string(i)+".out").c_str(), "w", stdout);
ketemu = 0;
for(int i=0;i<32;i++)
k1[i] = k2[i] = '0';
cin >> s;
cin >> awal >> akhir;
cout << "#FILE double " << i << endl;
BF(0,0);
BF(0,1);
}
}