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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| import re import numpy as np
def gettaable_byasm(): asm = """ mov [ebp+var_104], 1 mov [ebp+var_100], 1 mov [ebp+var_FC], 0 mov [ebp+var_F8], 1 mov [ebp+var_F4], 0 mov [ebp+var_F0], 0 mov [ebp+var_EC], 1 mov [ebp+var_E8], 0 mov [ebp+var_E4], 0 mov [ebp+var_E0], 1 mov [ebp+var_DC], 1 mov [ebp+var_D8], 0 mov [ebp+var_D4], 0 mov [ebp+var_D0], 1 mov [ebp+var_CC], 0 mov [ebp+var_C8], 1 mov [ebp+var_C4], 0 mov [ebp+var_C0], 0 mov [ebp+var_BC], 1 mov [ebp+var_B8], 1 mov [ebp+var_B4], 0 mov [ebp+var_B0], 1 mov [ebp+var_AC], 1 mov [ebp+var_A8], 0 mov [ebp+var_A4], 0 mov [ebp+var_A0], 0 mov [ebp+var_9C], 0 mov [ebp+var_98], 1 mov [ebp+var_94], 0 mov [ebp+var_90], 1 mov [ebp+var_8C], 0 mov [ebp+var_88], 1 mov [ebp+var_84], 0 mov [ebp+var_80], 1 mov [ebp+var_7C], 0 mov [ebp+var_78], 0 mov [ebp+var_74], 1 mov [ebp+var_70], 0 mov [ebp+var_6C], 1 mov [ebp+var_68], 0 mov [ebp+var_64], 0 mov [ebp+var_60], 0 mov [ebp+var_5C], 0 mov [ebp+var_58], 0 mov [ebp+var_54], 0 mov [ebp+var_50], 1 mov [ebp+var_4C], 0 mov [ebp+var_48], 1 mov [ebp+var_44], 0 mov [ebp+var_40], 0 mov [ebp+var_3C], 0 mov [ebp+var_38], 0 mov [ebp+var_34], 0 mov [ebp+var_30], 0 mov [ebp+var_2C], 1 mov [ebp+var_28], 1 mov [ebp+var_24], 0 mov [ebp+var_20], 1 mov [ebp+var_1C], 1 mov [ebp+var_18], 0 mov [ebp+var_14], 0 mov [ebp+var_10], 0 mov [ebp+var_C], 0 mov [ebp+var_8], 1 """ values = re.findall(r"mov.*?,\s*(\d+)", asm) values = [int(x) for x in values] return values
def exchange(input, tableM): inlen = len(input) for i in range(32): input[i], input[inlen - tableM[i] - 1] = input[inlen - tableM[i] - 1], input[i] return input
def deexchange(input, tableM): inlen = len(input) for i in range(32): input[inlen - tableM[i] - 1], input[i] = input[i], input[inlen - tableM[i] - 1] return input
def changeKey(key): data = [] for i in range(0, len(key), 2): data.append((((key[i] - 48)<<4) | (key[i + 1] - 48)) &0xff) return data
key2 = [53, 50, 54, 53, 53, 54, 54, 53, 53, 50, 54, 53, 53, 51, 54, 53] mm = [376, 356, 169, 501, 277, 329, 139, 342, 380, 365, 162, 258, 381, 339, 347, 307, 263, 359, 162, 484, 310, 333, 346, 339, 150, 194, 175, 344, 158, 250, 128, 175, 158, 173, 152, 379, 158, 292, 130, 365, 197, 20, 197, 161, 198, 10, 207, 244, 202, 14, 204, 176, 193, 255, 35, 7, 158, 181, 145, 353, 153, 357, 246, 151]
randi = [27, 26, 25, 23, 28, 1, 6, 10, 20, 7, 15, 14, 31, 18, 19, 21, 9, 30, 22, 24, 8, 2, 29, 3, 12, 11, 17, 16, 0, 13, 5, 4]
MatrixB = gettaable_byasm()
key = changeKey(key2)
for i in range(len(mm)): mm[i] ^= key[i % len(key)]
B = np.array(mm).reshape(-1,8) A = np.array(MatrixB).reshape(-1,8)
invA = np.linalg.inv(A) res = invA @ B
resl =deexchange(res.astype(int).flatten().tolist(),randi)
flag =''.join(map(chr,resl))
print(flag)
|