Description of the xxtea encryption algorithm and its c-realization
"micro-encrypted algorithms (teas) and their associated variants (xtea, block tea, xxtea) are cluster encrypted algorithms that are easy to describe and simple to achieve (typical lines of code)。
The tea algorithm was originally designed by david wheeler and roger needham at the cambridge computer laboratory in 1994. This algorithm is encrypted using a 64-bit message block with 128-bit keys. It requires 64 rotationals. The algorithm uses a mystical constant as a multiple, which is derived from the gold ratio to ensure that each round of encryption is different. But the precise value of the acquis does not seem to be important, and here tea defines it as "(√5-1) 231" (i. E. 0x9e3779b9 in the program)
In fact, tea is very close to us, because qq is using 16-round tea algorithms。
Xxtea, its latest variant, was introduced in 1998. No one has yet found a way to attack them, which is an improvement on some of the variables that lie ahead. Xxtea algorithms are safe and fast, and very suitable for web development。
Here is the c-realization of the algorithm given by the author:
#definine mx (z>5y3^z1)
Q = 6 + 52/n;
While (q -- > 0) {
Sum + = delta;
E = (sum > 2) & 3;
For (p=0; p)
Y = v;
Z = v + = mx;
Return 0;
If
= -n;
Q = 6 + 52/n;
Sum = q*delta;
While (sum! = 0) {
E = (sum > 2) & 3;
For (p=n-1; p>0; p-) z = v, y = v - = mx;
Z = v;
Y = v - = mx;
Sum - = delta;
Turn 0;
Return 1;
♪ will encode or decode the words as a single block where > 1
/is the word data vector
K is the 4 word key
No, no, no, no, no
If not is zero result is 1 and no coding or taking places, otherwise the result is zero
Assumes 32 bit 'long' and same endian coding and decoding
It's a wikipedia note. It's more obvious。
The central point is to understand that the xxtea algorithm encrypts 32bit-based information blocks using 128bit keys。
In this presentationThe word 'word' took me a long time. I started thinking "words," that's 2byte, 16bit. But after i spent a lot of time testing and experimenting, it's clear that word is not a unit here, probably to translate words like "assemblies", which is a 32bit type later。
That's all that matters. The code:
Long btea (long* v, long n, long* k)
V is the starting address of the encrypted block, in 32bit, and this is done with long。
N is the number of blocks to encrypt, positive number is encryption, negative number is decryption。
K is the initial address of the key and is four blocks long and 4*32=128bit。
Returns a value of 0 or 1 (n=0, not calculated)。
The encrypted result will go back to v。
The calculation of xxtea is space-related, i. E., four bytes cannot be taken out of context, i. E. A part of a secret text, and cannot be restored to an express part。
Therefore, when data cannot be divided by four bytes, byte filling and supporting tasks such as them are performed。










