longbtea(long* v, long n, long* k) { unsignedlong z=v[n-1], y=v[0], sum=0, e, DELTA=0x9e3779b9; long i, q ; if (n > 1) { q = 6 + 52/n; while (q-- > 0) { sum += DELTA; e = (sum >> 2) & 3; for (i=0; i<n-1; i++){ y = v[i+1]; z = v[i] += MX; } y = v[0]; z = v[n-1] += MX; } return0 ; }
elseif (n < -1) { n = -n; q = 6 + 52/n; sum = q*DELTA ; while (sum != 0) { e = (sum >> 2) & 3; for (i=n-1; i>0; i--) { z = v[i-1]; y = v[i] -= MX; } z = v[n-1]; y = v[0] -= MX; sum -= DELTA; } return0; } return1; } /* long btea(long* v, long n, long* k) v是要加密的组元的起始地址,以32bit为单位,这里用long来实现。
defencrypt(v, n, k): rounds = 6 + int(52 / n) sum = c_uint32(0) z = v[n - 1].value while rounds > 0: sum.value += DELTA e = (sum.value >> 2) & 3 p = 0 while p < n - 1: y = v[p + 1].value v[p].value += (((z >> 5 ^ y << 2) + (y >> 3 ^ z << 4)) ^ ((sum.value ^ y) + (k[(p & 3) ^ e] ^ z))) z = v[p].value p += 1 y = v[0].value v[n - 1].value += (((z >> 5 ^ y << 2) + (y >> 3 ^ z << 4)) ^ ((sum.value ^ y) + (k[(p & 3) ^ e] ^ z))) z = v[n - 1].value rounds -= 1
defdecrypt(v, n, k): rounds = 6 + int(52 / n) sum = c_uint32(rounds * DELTA) y = v[0].value while rounds > 0: e = (sum.value >> 2) & 3 p = n - 1 while p > 0: z = v[p - 1].value v[p].value -= (((z >> 5 ^ y << 2) + (y >> 3 ^ z << 4)) ^ ((sum.value ^ y) + (k[(p & 3) ^ e] ^ z))) y = v[p].value p -= 1 z = v[n - 1].value v[0].value -= (((z >> 5 ^ y << 2) + (y >> 3 ^ z << 4)) ^ ((sum.value ^ y) + (k[(p & 3) ^ e] ^ z))) y = v[0].value sum.value -= DELTA rounds -= 1
if __name__ == '__main__': key = [0x4DB, 0xE, 0x17, 0x2A6] enc = [3364074410, 133904720, 1975277913, 2058714663, 3223623680, 2913163091, 3206367551, 1846849284, 1182995140] v = [] for i in enc: v.append(c_uint32(i)) decrypt(v, len(v), key) flag = '' for i inrange(len(v)): a = v[i].value for j inrange(4): flag += chr(a & 0xff) a >>= 8 print(flag)