-
Notifications
You must be signed in to change notification settings - Fork 0
/
puzzle_10_2.cc
59 lines (51 loc) · 1.38 KB
/
puzzle_10_2.cc
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
#include <array>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
const unsigned NUMS = 256;
int main() {
std::vector<unsigned> lengths;
std::string line;
std::getline(std::cin, line);
for (const unsigned& c : line) {
lengths.push_back(c);
}
lengths.push_back(17);
lengths.push_back(31);
lengths.push_back(73);
lengths.push_back(47);
lengths.push_back(23);
std::array<unsigned char, NUMS> nums;
for (unsigned i = 0; i < NUMS; ++i) {
nums[i] = i;
}
int skip = 0;
int pos = 0;
for (unsigned round = 0; round < 64; ++round) {
for (auto w : lengths) {
int from = pos, to = (pos + w - 1) % NUMS;
for (unsigned i = w / 2; i > 0; --i) {
std::swap(nums[from], nums[to]);
from = ++from % NUMS;
if (to == 0) {
to = NUMS;
}
to -= 1;
}
pos = (pos + w + skip++) % NUMS;
}
}
std::array<unsigned, 16> dense;
for (int i=0; i<16; ++i) {
int from = 16*i;
int to = 16*(i+1);
unsigned char h = nums[from];
for (++from; from < to; ++from) {
h ^= nums[from];
}
dense[i] = h;
std::cout << std::hex << std::setw(2) << std::setfill('0') << (unsigned)h;
}
std::cout << "\n";
}