XXTEA算法的C语言实现
#define DELTA 0x9e3779b9 #define MX (((z>>5^y<<2) + (y>>3^z<<4)) ^ ((sum^y) + (key[(p&3)^e] ^ z))) #define XXTEA_ENCODE_MODE 0 #define XXTEA_DECODE_MODE 1 void xxtea(unsigned int *v, int n, const unsigned int key[], int mode) { unsigned int y, z, sum; unsigned int p, rounds, e; if(n <= 1) return; if(mode == XXTEA_ENCODE_MODE) { /* Coding Part */ rounds = 6 + 52/n; sum = 0; z = v[n - 1]; do { sum += DELTA; e = (sum >> 2) & 3; for(p = 0; p < n - 1; p++) { y = v[p + 1]; z = v[p] += MX; } y = v[0]; z = v[n - 1] += MX; }while(--rounds); } else if(mode == XXTEA_DECODE_MODE) { /* Decoding Part */ rounds = 6 + 52/n; sum = rounds * DELTA; y = v[0]; do { e = (sum >> 2) & 3; for(p = n - 1; p > 0; p--) { z = v[p - 1]; y = v[p] -= MX; } z = v[n - 1]; y = v[0] -= MX; sum -= DELTA; }while(--rounds); } return; }
相关推荐
chensen 2020-11-14
拉斯厄尔高福 2020-11-04
杜倩 2020-10-29
拉斯厄尔高福 2020-10-19
嵌入式资讯精选 2020-10-15
zhaochen00 2020-10-13
penkgao 2020-10-13
yiyilanmei 2020-10-05
wanshiyingg 2020-09-29
Mars的自语 2020-09-27
shenwenjie 2020-09-24
一个逗逗 2020-09-22
flycony 2020-09-13
zhaochen00 2020-08-20
Biao 2020-08-20
qingsongzdq 2020-08-19
penkgao 2020-08-17
cetrolchen 2020-08-14
GuoSir 2020-08-07