from Crypto.Util.number import * import sympy as sp n = 16 q = 251
A = sp.Matrix([[105, 89, 18, 60, 188, 191, 82, 52, 202, 219, 237, 130, 219, 182, 150, 188], [20, 238, 248, 53, 181, 54, 37, 165, 217, 214, 10, 97, 26, 159, 182, 229], [152, 138, 120, 12, 217, 142, 102, 35, 99, 30, 110, 87, 248, 126, 86, 244], [205, 87, 97, 108, 155, 244, 203, 146, 242, 58, 77, 42, 26, 11, 5, 61], [70, 37, 201, 185, 242, 154, 96, 146, 50, 108, 42, 186, 58, 44, 24, 199], [141, 189, 16, 171, 174, 38, 224, 9, 155, 221, 16, 136, 39, 28, 141, 142], [184, 6, 139, 103, 147, 187, 225, 163, 121, 34, 195, 66, 7, 234, 106, 228], [235, 136, 194, 7, 132, 173, 18, 242, 130, 136, 165, 73, 213, 141, 25, 0], [ 31, 135, 155, 153, 54, 88, 155, 36, 240, 190, 75, 24, 180, 64, 117, 124], [178, 165, 202, 150, 240, 235, 130, 200, 171, 126, 2, 206, 66, 45, 69, 17], [9, 68, 29, 44, 111, 44, 130, 171, 83, 13, 249, 192, 119, 178, 32, 217], [243, 244, 47, 94, 100, 245, 234, 103, 222, 66, 73, 126, 226, 48, 94, 13], [222, 75, 7, 108, 70, 216, 203, 92, 173, 111, 149, 152, 140, 71, 242, 135], [241, 42, 202, 9, 29, 95, 174, 131, 104, 114, 209, 109, 111, 219, 61, 233], [98, 4, 19, 214, 55, 38, 183, 28, 98, 218, 79, 95, 208, 190, 142, 176], [78, 0, 13, 65, 10, 141, 76, 114, 207, 226, 141, 148, 131, 98, 4, 88]])
b = sp.Matrix([[21], [239], [87], [61], [160], [26], [229], [222], [ 112], [216], [129], [91], [199], [181], [196], [19]])
c1 = sp.Matrix([[72, 91, 249, 87, 237, 196, 241, 146, 75, 108, 128, 192, 10, 105, 154, 140], [14, 131, 170, 198, 238, 120, 23, 242, 0, 83, 115, 64, 44, 241, 83, 112], [187, 132, 154, 137, 232, 165, 128, 2, 237, 239, 124, 184, 126, 188, 173, 150], [169, 178, 164, 177, 77, 35, 64, 63, 53, 82, 176, 141, 205, 7, 33, 72], [64, 206, 126, 198, 144, 42, 53, 183, 101, 218, 111, 39, 135, 164, 47, 181], [33, 2, 223, 70, 212, 131, 215, 155, 243, 15, 183, 227, 113, 66, 242, 38], [192, 210, 131, 161, 213, 68, 216, 168, 95, 18, 190, 174, 220, 148, 191, 230], [88, 216, 134, 40, 156, 95, 210, 87, 94, 74, 18, 31, 124, 191, 197, 92], [ 151, 222, 133, 56, 240, 89, 220, 221, 23, 109, 162, 206, 225, 134, 44, 142], [25, 242, 210, 33, 250, 62, 85, 134, 189, 232, 86, 113, 56, 239, 57, 31], [220, 18, 168, 173, 139, 192, 185, 237, 169, 15, 39, 119, 205, 72, 237, 2], [178, 2, 215, 71, 58, 161, 154, 207, 45, 56, 186, 51, 25, 116, 81, 43], [20, 103, 20, 234, 145, 161, 156, 99, 114, 85, 16, 162, 34, 19, 45, 92], [193, 77, 56, 233, 34, 76, 47, 163, 106, 228, 66, 63, 100, 223, 211, 123], [69, 208, 156, 39, 236, 39, 25, 166, 242, 31, 103, 171, 154, 220, 140, 93], [72, 125, 173, 20, 70, 200, 101, 69, 74, 58, 143, 40, 117, 235, 124, 90]])
c2 = sp.Matrix([[1], [89], [8], [219], [220], [114], [73], [130], [ 142], [147], [250], [167], [113], [237], [61], [201]])
x = (c1*A.inv_mod(q)) % q cc = (x * b) % q for i in cc: print(i, end=' ') print() for i in cc: print((i+125) % 251, end=' ') print() for i in c2: print(i, end=' ') print()
a = int('1111110100010010', 2) print(hex(a)[2:])
|