-
Notifications
You must be signed in to change notification settings - Fork 588
/
test-subbreak3.cpp
55 lines (41 loc) · 1.7 KB
/
test-subbreak3.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
#include "subbreak3.h"
int main(int argc, char ** argv) {
printf("Usage: %s n-gram.txt\n", argv[0]);
if (argc < 2) {
return -1;
}
Cipher::TFreqMap freqMap;
if (Cipher::loadFreqMapBinary((std::string(argv[1]) + ".binary").c_str(), freqMap) == false) {
if (Cipher::loadFreqMap(argv[1], freqMap) == false) {
return -1;
}
Cipher::saveFreqMapBinary((std::string(argv[1]) + ".binary").c_str(), freqMap);
}
//if (Cipher::loadFreqMap(argv[1], freqMap) == false) {
// return -1;
//}
std::string plain = R"(
Dave found joy in the daily routine of life. He awoke at the same time, ate the same breakfast and drove the same commute. He worked at a job that never seemed to change and he got home at 6 pm sharp every night. It was who he had been for the last ten years and he had no idea that was all about to change.
)";
Cipher::TParameters params;
Cipher::TResult result;
Cipher::encryptExact(params, plain, result.clusters);
Cipher::printEncoded(result.clusters);
{
std::map<TClusterId, char> answer;
for (int i = 0; i < (int) result.clusters.size(); ++i) {
answer[result.clusters[i]] = plain[i];
}
for (auto & p : answer) {
printf(" answer: '%c' -> '%c'\n", Cipher::getEncodedChar(p.first), p.second);
}
}
{
auto tStart = std::chrono::high_resolution_clock::now();
Cipher::beamSearch(params, freqMap, result);
auto tEnd = std::chrono::high_resolution_clock::now();
auto tDiff = std::chrono::duration_cast<std::chrono::milliseconds>(tEnd - tStart);
printf("Time: %ld ms\n", tDiff.count());
}
return 0;
}