TEA 因为网上大多tea加密都是用的c
所以我这里也用C
2023.11.8做了一个新题
加密:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 __int64 __fastcall main (int a1, char **a2, char **a3) { int i; _QWORD input[6 ]; input[5 ] = __readfsqword(0x28 u); puts ("plz input u fl4g:" ); __isoc99_scanf("%32s" , input); sub_400763(); for ( i = 0 ; i <= 3 ; ++i ) sub_400696(&input[i], &dword_601080); if ( !memcmp (input, &dword_6010A0, 0x20 uLL) ) puts ("yeh~" ); else puts ("oh,no" ); return 0LL ; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 __int64 __fastcall sub_400696 (unsigned int *a1, _DWORD *k) { __int64 result; unsigned int v3; unsigned int v4; int v5; unsigned int i; v3 = *a1; v4 = a1[1 ]; v5 = 0 ; for ( i = 0 ; i <= 0x1F ; ++i ) { v5 -= 1640531527 ; v3 += (v4 + v5) ^ (16 * v4 + *k) ^ ((v4 >> 5 ) + k[1 ]); v4 += (v3 + v5) ^ (16 * v3 + k[2 ]) ^ ((v3 >> 5 ) + k[3 ]); } *a1 = v3; result = v4; a1[1 ] = v4; return result; }
解密:
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 #include <cstdio> #include <stdint.h> #include <stdlib.h> void decrypt (unsigned int * v, const unsigned int * k) { uint32_t v3 = v[0 ]; uint32_t v4 = v[1 ]; uint32_t v5 = ((-1640531527 ) * 32 ) & 0xFFFFFFFF ; for (int i = 0 ; i <= 31 ; ++i) { v4 -= (v3 + v5) ^ (16 * v3 + k[2 ]) ^ ((v3 >> 5 ) + k[3 ]); v3 -= (v4 + v5) ^ (16 * v4 + k[0 ]) ^ ((v4 >> 5 ) + k[1 ]); v5 += 1640531527 ; } v[0 ] = v3; v[1 ] = v4; } int main () { unsigned int v[8 ] = { 0x0DB8F2569 ,0x40CD83E3 ,0xA033E680 ,0xFFF7A644 , 0x690C3A17 ,0x0B621B866 ,0x34E7E2A7 ,0xAD10A692 }; unsigned int k[4 ] = { 0x01234567 , 0x89ABCDEF , 0xFEDCBA98 , 0x76543210 }; for (int i = 0 ; i < 8 ; i += 2 ) { decrypt(v + i, k); } for (int i = 0 ; i < 8 ; i++) { printf ("%xh\n" , v[i]); } unsigned char flag[32 ]; for (int i = 0 ; i < 8 ; i++) { for (int j = 0 ; j < 4 ; j++) { flag[i * 4 + j] = (v[i] >> (j * 8 )) & 0xFF ; } } printf ("flag[32] = {" ); for (int i = 0 ; i < 32 ; i++) { printf ("0x%02X" , flag[i]); if (i < 31 ) { printf (", " ); } } printf ("}\n" ); for (int i = 0 ; i < 32 ; i++) { printf ("%c" , flag[i]); } }
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 #include <cstdio> void decrypt (unsigned int * v, const unsigned int * k) { int v6 = v[0 ]; int v5 = v[1 ]; int v4 = 0xC6EF3720 ; for (int i = 0 ; i <= 31 ; ++i) { v4 -= 0x61C88647 ; v6 += (v5 + v4) ^ (k[0 ] + 16 * v5) ^ ((v5 >> 5 ) + k[1 ]); v5 += (v6 + v4) ^ (k[2 ] + 16 * v6) ^ ((v6 >> 5 ) + k[3 ]); } v[0 ] = v6; v[1 ] = v5; } int main () { unsigned int v[] = { 0x6B046D5E , 0x0F38A133E , 0x4F6144D9 , 0x5A22624B , 0x600DD811 , 0x3A15D5A5 , 0x1A9C6DBF , 0x0F6C94ADD , 0x0F99AFF46 ,0x0CE3C1008 , 0x92CA6FEC , 0x4C98D1D0 , 0x6F0AB52C , 0x1C4EE3F1 , 0x0B5B5650D , 0x0EBCC67DE }; unsigned int k[4 ] = { 0x1145 , 0x5140 , 0x5140 , 0x8100 }; for (int i = 0 ; i <= 15 ; i += 2 ) { decrypt(v+i, k); } for (int i = 0 ; i <= 15 ; i++) { printf ("%Xh " , v[i]); } }
XXTEA 当这个遇到base64的时候就可以用在线网站解开: