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
| #include <stdio.h> #include <stdint.h> #define DELTA 0x9e3779b9 #define MX (((z >> 5 ^ y << 2) + (y >> 3 ^ z << 4)) ^ ((sum ^ y) + (key[(p & 3) ^ e] ^ z)))
void btea(uint32_t *v, int n, uint32_t const key[4]) { uint32_t y, z, sum; unsigned p, rounds, e; if (n > 1) { rounds = 6 + 52 / n; sum = DELTA; z = v[n - 1]; do { e = (sum >> 2) & 3; for (p = 0; p < n - 1; p++) { y = v[p + 1]; z = v[p] += MX; } y = v[0]; z = v[n - 1] += MX; sum -= 0x61C88647; } while (--rounds); } else if (n < -1) { n = -n; rounds = 6 + 52 / n; sum = rounds * DELTA; y = v[0]; do { e = (sum >> 2) & 3; for (p = n - 1; p > 0; p--) { z = v[p - 1]; y = v[p] -= MX; } z = v[n - 1]; y = v[0] -= MX; sum += 0x61C88647; } while (--rounds); } }
int main() { uint32_t const k[4] = {0x72, 0x202, 0x13, 0x13}; int n = 2;
btea(v, n, k); printf("解密后的数据:%x %x\n", v[0], v[1]); return 0; }
s1 = [0x8D, 0xE2, 0x3D, 0xC2, 0x19, 0xF2, 0x2D, 0xCA, 0x18, 0x14, 0xCF, 0x52, 0x77, 0x5A, 0x9C, 0x13, 0xAA, 0xCC, 0x04, 0x5B, 0x92, 0xC1, 0x0C, 0x68, 0x45, 0x58, 0xF9, 0x47, 0x68, 0xD9, 0x35, 0xC5] s2 = [0xEB, 0x8E, 0x5C, 0xA5, 0x62, 0xB4, 0x1C, 0x84, 0x5C, 0x59, 0xFC, 0x0D, 0x43, 0x3C, 0xAB, 0x20, 0xD8, 0x93, 0x33, 0x13, 0xA1, 0x9E, 0x39, 0x00, 0x76, 0x14, 0xB5, 0x04, 0x58, 0x9D, 0x06, 0xB8] flag = "" for i in range(32): flag += chr(s1[i] ^ s2[i]) print(flag)
|