|
@@ -0,0 +1,29 @@
|
|
1
|
+#!/usr/bin/python3
|
|
2
|
+
|
|
3
|
+import itertools
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+def expand(state, length):
|
|
7
|
+ while len(state) < length:
|
|
8
|
+ state = list(itertools.chain(state, [False], (not x for x in reversed(state))))
|
|
9
|
+ return state[:length]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+def checksum_round(state):
|
|
13
|
+ return [state[i] == state[i + 1] for i in range(0, len(state), 2)]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+def checksum(state):
|
|
17
|
+ state = checksum_round(state)
|
|
18
|
+ while len(state) % 2 == 0:
|
|
19
|
+ state = checksum_round(state)
|
|
20
|
+ return state
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+def run(state, size):
|
|
24
|
+ return ''.join(str(int(x)) for x in checksum(expand(state, size)))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+iv = [bool(int(x)) for x in '01110110101001000']
|
|
28
|
+print('Step 1: %s' % run(iv, 272))
|
|
29
|
+print('Step 2: %s' % run(iv, 35651584))
|