注意的是逆向得时候 sum=delta*32
#include <stdio.h> #include <stdint.h> void encrypt (uint32_t* v, uint32_t* k) { // 涓昏鍔犲瘑鍑芥暟锛岃瘯鐫€鎼炲畾瀹? uint32_t v0 = v[0], v1 = v[1], sum = 0; uint32_t delta = 0xd33b470; for (int i = 0; i < 32; i++) { sum += delta; v0 += ((v1<<4) + k[0]) ^ (v1 + sum) ^ ((v1>>5) + k[1]); v1 += ((v0<<4) + k[2]) ^ (v0 + sum) ^ ((v0>>5) + k[3]); } v[0] = v0; v[1] = v1; } int main() { uint32_t k[4] = {1, 2, 3, 4}; int8_t input[33] = {0}; scanf("%32s", input); for (int i = 0; i < 32; i+=8) { uint32_t v[2] = {*(uint32_t *)&input[i], *(uint32_t *)&input[i+4]}; encrypt(v, k); for (int j = 0; j < 2; j++) { // 杩欎竴娈典富瑕佹槸鎶?v 鎸夊崟瀛楄妭杈撳嚭锛屽彟澶栧彲浠ヤ簡瑙d竴涓?鈥滃ぇ灏忕搴忊€?鍦ㄨ繖棰樻槸濡備綍浣撶幇鐨? for (int k = 0; k < 4; k++) { printf("%#x, ", v[j] & 0xff); v[j] >>= 8; } } } return 0; }
#include <stdio.h> #include <stdint.h> void encrypt(uint32_t* v, uint32_t* k) { uint32_t v0 = v[0], v1 = v[1], sum = 0xd33b470*32; uint32_t delta = 0xd33b470; for (int i = 0; i < 32; i++) { v1 -= ((v0 << 4) + k[2]) ^ (v0 + sum) ^ ((v0 >> 5) + k[3]); v0 -= ((v1 << 4) + k[0]) ^ (v1 + sum) ^ ((v1 >> 5) + k[1]); sum -= delta; } v[0] = v0; v[1] = v1; } int main() { uint32_t k[4] = {1, 2, 3, 4}; uint8_t input[32] = {0x17, 0x65, 0x54, 0x89, 0xed, 0x65, 0x46, 0x32, 0x3d, 0x58, 0xa9, 0xfd, 0xe2, 0x5e, 0x61, 0x97, 0xe4, 0x60, 0xf1, 0x91, 0x73, 0xe9, 0xe9, 0xa2, 0x59, 0xcb, 0x9a, 0x99, 0xec, 0xb1, 0xe1, 0x7d}; for (int i = 0; i < 32; i += 8) { uint32_t v[2] = { *(uint32_t*)&input[i], *(uint32_t*)&input[i + 4] }; encrypt(v, k); for (int j = 0; j < 2; j++) { for (int k = 0; k < 4; k++) { printf("%c", v[j] & 0xff); v[j] >>= 8; } } } printf("\n"); return 0; }
moectf{Th3_TEA_!S_s0_t4s7y~~!!!}