This repository has been archived by the owner on May 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathservice2_store2_common_sage.sage
34 lines (30 loc) · 2.58 KB
/
service2_store2_common_sage.sage
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
from bitstring import BitArray
def get_key(bdata):
mat = [[17, 19, 20, 23], [17, 18, 20, 23], [17, 23], [17, 18, 19, 21], [16, 21, 22, 23], [16, 17, 18, 19, 22], [20, 23], [17, 18, 19, 22], [25, 27, 28, 31], [25, 26, 28, 31], [25, 31], [25, 26, 27, 29], [24, 29, 30, 31], [24, 25, 26, 27, 30], [28, 31], [25, 26, 27, 30], [33, 35, 36, 39], [33, 34, 36, 39], [33, 39], [33, 34, 35, 37], [32, 37, 38, 39], [32, 33, 34, 35, 38], [36, 39], [33, 34, 35, 38], [41, 43, 44, 47], [41, 42, 44, 47], [41, 47], [41, 42, 43, 45], [40, 45, 46, 47], [40, 41, 42, 43, 46], [44, 47], [41, 42, 43, 46], [65, 67, 68, 71], [65, 66, 68, 71], [65, 71], [65, 66, 67, 69], [64, 69, 70, 71], [64, 65, 66, 67, 70], [68, 71], [65, 66, 67, 70], [73, 75, 76, 79], [73, 74, 76, 79], [73, 79], [73, 74, 75, 77], [72, 77, 78, 79], [72, 73, 74, 75, 78], [76, 79], [73, 74, 75, 78], [89, 91, 92, 95], [89, 90, 92, 95], [89, 95], [89, 90, 91, 93], [88, 93, 94, 95], [88, 89, 90, 91, 94], [92, 95], [89, 90, 91, 94], [97, 99, 100, 103], [97, 98, 100, 103], [97, 103], [97, 98, 99, 101], [
100, 103], [97, 98, 99, 102], [105, 107, 108, 111], [105, 106, 108, 111], [105, 111], [105, 106, 107, 109], [108, 111], [105, 106, 107, 110], [113, 115, 116, 119], [113, 114, 116, 119], [113, 119], [113, 114, 115, 117], [116, 119], [113, 114, 115, 118], [121, 123, 124, 127], [121, 122, 124, 127], [121, 127], [121, 122, 123, 125], [124, 127], [121, 122, 123, 126], [81, 83, 84, 87], [81, 82, 84, 87], [81, 87], [81, 82, 83, 85], [80, 85, 86, 87], [80, 81, 82, 83, 86], [84, 87], [81, 82, 83, 86], [49, 51, 52, 55], [49, 50, 52, 55], [49, 55], [49, 50, 51, 53], [48, 53, 54, 55], [48, 49, 50, 51, 54], [52, 55], [49, 50, 51, 54], [57, 59, 60, 63], [57, 58, 60, 63], [57, 63], [57, 58, 59, 61], [56, 61, 62, 63], [56, 57, 58, 59, 62], [60, 63], [57, 58, 59, 62], [1, 3, 4, 7], [1, 2, 4, 7], [1, 7], [1, 2, 3, 5], [0, 5, 6, 7], [0, 1, 2, 3, 6], [4, 7], [1, 2, 3, 6], [9, 11, 12, 15], [9, 10, 12, 15], [9, 15], [9, 10, 11, 13], [8, 13, 14, 15], [8, 9, 10, 11, 14], [12, 15], [9, 10, 11, 14]]
K = GF(2)
M = []
for row in mat:
cur = [0]*128
for x in row:
cur[x] = 1
M.append(cur)
M = Matrix(K, M)
bb = []
mm = []
# ASCII stuff
for i in range(7, 128, 8):
row = [0]*128
row[i] = 1
mm.append(row)
bb.append(0)
b2 = vector(K, bdata+bb)
M2 = M.stack(Matrix(K, mm))
res = M2.solve_right(b2)
keys = []
for v in M2.right_kernel():
sol = res+v
arr = [int(x) for x in sol[::-1]]
boh = BitArray(arr)
keys.append(boh.bytes)
return keys