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
关键词:
AVR
数组
studio
atmel