-
Notifications
You must be signed in to change notification settings - Fork 0
/
10.py
55 lines (38 loc) · 936 Bytes
/
10.py
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
from lib import *
input = read_input(2017, 10).strip()
nums = [*range(256)]
pos = 0
skip = 0
def rev(a, b):
a %= len(nums)
b = (b - a) % len(nums)
nums[:] = nums[a:] + nums[:a]
nums[:b] = nums[:b][::-1]
nums[:] = nums[-a:] + nums[:-a]
for length in map(int, input.split(",")):
rev(pos, pos + length)
pos += length + skip
skip += 1
print(nums[0] * nums[1])
lengths = [*map(ord, input), 17, 31, 73, 47, 23]
nums = [*range(256)]
pos = 0
skip = 0
def rev(a, b):
a %= len(nums)
b = (b - a) % len(nums)
nums[:] = nums[a:] + nums[:a]
nums[:b] = nums[:b][::-1]
nums[:] = nums[-a:] + nums[:-a]
for _ in range(64):
for length in lengths:
rev(pos, pos + length)
pos += length + skip
skip += 1
dense = []
for i in range(16):
x = 0
for j in range(16):
x ^= nums[i * 16 + j]
dense.append(x)
print("".join(f"{x:02x}" for x in dense))