void main()
{
//UART1_Init();
unsigned long plainbuffer[2];
unsigned long testbuffer[4];
unsigned long plain[2]={0x23FF28AA,0x23FF28AA};
unsigned long test[4]={0x01122334,0x45566778,0x899AABBC,0xCDDEEFF0};
unsigned long key[4]={0x01234567,0x89ABCDEF,0x01234567,0x89ABCDEF};
while(1)
{
memcpy(plainbuffer,plain,8);
memcpy(testbuffer,test,16);
tea_encrypt(plainbuffer,key);
tea_decrypt(plainbuffer,key);
}
}
void tea_encrypt(unsigned long *v, unsigned long* k)
{
unsigned long v0=v[0], v1=v[1], sum=0, i;
unsigned long delta=0x9e3779b9;
unsigned long k0=k[0], k1=k[1], k2=k[2], k3=k[3];
for (i=31; i < 32; 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;
}
这个为什么key数组穿不进函数里面?进去后k0,1,2,3全是0
有奖活动 | |
---|---|
【有奖活动——B站互动赢积分】活动开启啦! | |
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |