#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++) { for (int k = 0; k < 4; k++) { printf("%#x, ", v[j] & 0xff); v[j] >>= 8; } } } return 0; }
exp
#include <stdio.h> #include <stdint.h> void decrypt(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 };//uint32_t——4字节,uint8_t——1字节 int8_t input[] = { 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] };//1字节强制转换为4字节 decrypt(v, k);//加密 for (int j = 0; j < 2; j++)//一字节一字节打印出来 { for (int k = 0; k < 4; k++) { printf("%c", v[j] & 0xff); v[j] >>= 8; } } } return 0; }
标签:v1,ezTea,++,v0,int,2022,MoeCTF,input,uint32 From: https://www.cnblogs.com/lhqrusht0p/p/17854748.html