re [MTCTF 2022]small 复现

直接看汇编,

 是tea,稍微改了一下,加密35轮,

void encrypt(uint32_t* v, uint32_t* k) {
	uint32_t v0 = v[0], v1 = v[1], sum = 0, i;
	uint32_t delta = 0x67452301;
	uint32_t k0 = k[0], k1 = k[1], k2 = k[2], k3 = k[3];
	for (i = 0; i < 35; i++) {
		sum += delta;
		v0 += ((v1 << 4) + k0) ^ (v1 + sum) ^ ((v1 >> 5) + k1);
		v1 += ((v0 << 4) + k2) ^ (v0 + sum) ^ ((v0 >> 5) + k3);
	}
	v[0] = v0; v[1] = v1;
}

//解密函数
void decrypt(uint32_t* v, uint32_t* k) {
	uint32_t v0 = v[0], v1 = v[1], sum = 0x67452301*35, i;
	uint32_t delta = 0x67452301;
	uint32_t k0 = k[0], k1 = k[1], k2 = k[2], k3 = k[3];
	for (i = 0; i<35; i++) {
		v1 -= ((v0 << 4) + k2) ^ (v0 + sum) ^ ((v0 >> 5) + k3);
		v0 -= ((v1 << 4) + k0) ^ (v1 + sum) ^ ((v1 >> 5) + k1);
		sum -= delta;
	}
	v[0] = v0; v[1] = v1;
}

int main()
{
	int i ,j;
	// v为要加解密的数据,两个32位无符号整数
	uint32_t v[2] = {  0x646f6f67, 0x050FF789};//89 F7 0F 05
	//0x646f6f67,0xde087143,0xc4f91bd2,0xdaf6dadc,0x6d9ed54c,0x75eb4ee7,0x5d1ddc04,0x511b0fd9,0x51dc88fb,
	// k为加解密密钥,4个32位无符号整数,密钥长度为128位
	uint32_t k[4] = { 0x1,0x23,0x45,0x67 };
	int n = sizeof(v) / sizeof(uint32_t);
	
	printf("加密后的数据:0x%x 0x%x\n", v[0], v[1]);
	decrypt(v, k);
	printf("解密后的数据:0x%x 0x%x\n", v[0], v[1]);
	for ( i = 0; i < n; i++)
	{
		for ( j = 0; j < sizeof(uint32_t)/sizeof(uint8_t); j++)
		{
			printf("%d,", (v[i] >> (j * 8)) & 0xFF);
		}
	}
	printf("\n");
	return 0;
}

改一下就行

flag:327a6c4304ad5938eaf0efb6cc3e53dc

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值