-
Notifications
You must be signed in to change notification settings - Fork 2
/
decode_chute.py
70 lines (50 loc) · 1.96 KB
/
decode_chute.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# mars perseverance parachute color coding inner ring 0 to outer ring 3 (W)hite (R)ed
chuteseg = ["WWWWWWWRWWWWWWWWWWWRWWWWWRWWRWWWWWWWWRWRWWWRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR",
"WWWWWRWRWWWWWWWRRWWRWWWRRRRRRRRRRRRRRRRRWWWWWWRRWRWWWWWWRWWRWWWWWWWRRRWWWWWWRWWW",
"WWWRRRRRRRRRRRRRRRRRWWWWWRWRWWWWWWWWRWWWWWWWWWRWWRWWWWWWRRRWWWWWWWWRRRWWWWWRWWRR",
"WWWWRWWWRWWWWWWWRWRRWWWWRRRWRWWWWWWWRRRWWWWRRRWRRWWWWWWWRWRWWWWWWRRRRRWWWWWRWRRR"]
# bit chunk size of the code sequence
chunksize = 10
# decode rings color white(0) red(1)
chutecodes = []
for seg in chuteseg:
bin = seg.replace("W", "0")
bin = bin.replace("R", "1")
chutecodes.append(bin)
# dump all 80 ring 0 rotations
bits = list(chutecodes[0])
for s in range(len(bits)):
# rotate ring code to start position
code = ''.join(bits[s:] + bits[:s])
print(code)
# simple scan for ascii offsets
for d in range(128):
for chutecode in chutecodes:
bits = list(chutecode)
matches = 0
# bit shift code to any of the possible start positions
for s in range(len(bits)):
# rotate ring code to start position
code = ''.join(bits[s:] + bits[:s])
text = ""
letters = 0
nums = []
chars = []
# process the chunks of the ring code
for i in range(len(code) // chunksize):
chunk = code[i * chunksize: i * chunksize + chunksize]
# parse int from chunk bits
num = int(chunk, 2)
nums.append(num)
# add ascii scan offset
chrnum = num + d
char = chr(chrnum)
text += char
# count uppercase letters
if chrnum >= 65 and chrnum <= 90:
letters += 1
if letters > 3:
matches += 1
print(d, s, text, nums)
if matches > 0:
print()