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
| def rol(x, n): return ((x << n) | (x >> (8 - n))) & 0xFF
def ror(x, n): return ((x >> n) | (x << (8 - n))) & 0xFF
def unxor_chain(data): temp = [0] * len(data) for i in range(len(data)): if i == 0: temp[i] = data[i] ^ 0x42 else: temp[i] = (data[i] ^ data[i-1]) ^ 0x42 return temp
def generate_sbox(): s = list(range(256)) j = 0 for i in range(256): j = (j + s[i] - 7*(i//7) + i + 4919) % 256 s[i], s[j] = s[j], s[i] return s
def decrypt_flag(target): temp_v24 = unxor_chain(target) s = generate_sbox()
i = 0 j = 0 flag = []
for idx in range(len(temp_v24)): i = (i + 1) % 256
if i % 3 == 0: j = (j + s[3 * i % 256]) % 256 else: j = (j + s[i]) % 256
old_si = s[i] old_sj = s[j] s[i], s[j] = s[j], s[i]
index = (old_si + s[i]) & 0xFF ks = s[index]
bias = (i * j) % 16
decrypted_val = ror(temp_v24[idx], 3) xor_val = decrypted_val - bias xor_val &= 0xFF
flag_char = xor_val ^ ks flag.append(flag_char)
return bytes(flag).decode('ascii', errors='replace')
target = [ 0x93, 0xF9, 0x8D, 0x92, 0x52, 0x57, 0xD9, 0x05, 0xC6, 0x0A, 0x50, 0xC7, 0xDB, 0x4F, 0xCB, 0xD8, 0x5D, 0xA6, 0xB9, 0x40, 0x95, 0x70, 0xE7, 0x9A, 0x37, 0x72, 0x4D, 0xEF, 0x57 ]
flag = decrypt_flag(target) print("Flag:", flag)
|