voidbtea(uint32_t *v, int n, uint32_tconst key[4]) { uint32_t y, z, sum; unsigned p, rounds, e; if (n > 1) /* 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); } elseif (n < -1) /* Decoding Part */ { n = -n; 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); } }
voidbtea(uint32_t *v, int n, uint32_tconst key[4]) { uint32_t y, z, sum; unsigned p, rounds, e; if (n > 1) /* Coding Part */ { rounds = 415 / n + 114; 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); } elseif (n < -1) /* Decoding Part */ { n = -n; rounds = 415 / n + 114; sum = 0x52b8cc1f;//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); } }
intmain() { uint32_t v[11]= {0x480AC20C,0xCE9037F2,0x8C212018,0xE92A18D,0xA4035274,0x2473AAB1,0xA9EFDB58,0xA52CC5C8,0xE432CB51,0xD04E9223,0x6FD07093}; uint32_tconst k[4]= {0x79696755,0x67346F6C,0x69231231,0x5F674231}; int n= 11; // btea(v, n, k); //printf("0x%0x",k[3]); btea(v, -n, k); printf("%s",v);
voidbtea(uint32_t *v, int n, uint32_tconst key[4]) { uint32_t y, z, sum; unsigned p, rounds, e; if (n > 1) /* Coding Part */ { rounds = 6 + 52 / n ; sum = 0; z = v[n-1]; do { sum += DELTA;A 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); } elseif (n < -1) /* Decoding Part */ { n = -n; rounds = 6 + 52 / n ; sum = rounds*DELTA;/*0xbdf7dc00*/; //这次可以用round*常数,也可以动调 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); } }