Algorithm is simple, and high efficiency, each can operate 8 bytes of data, encryption and decryption key for 16 bytes, that is, 4 int data of the int array, the number of encryption wheel should be 8 multiples, generally more commonly used in the number of rounds for 64,32,16,QQ originally is used TEA16 to restore the password.
Tea algorithm
The core is:
#include <stdint.h>
void Encrypt (uint32_t* V, uint32_t* k) {
uint32_t v0=v[0], v1=v[1], sum=0, I; /* Set up/*
uint32_t delta=0x9e3779b9; /* A key schedule constant * *
uint32_t k0=k[0], k1=k[1], k2=k[2], k3=k[3]; /* Cache Key * *
for (i=0 i < i++) {/* Basic cycle start */
sum = Delta;
V0 + = ((v1<<4) + k0) ^ (v1 + sum) ^ ((v1>>5) + K1);
V1 + = ((v0<<4) + K2) ^ (v0 + sum) ^ ((v0>>5) + K3);
}/* End cycle * *
V[0]=v0; V[1]=V1;
}
void Decrypt (uint32_t* V, uint32_t* k) {
uint32_t v0=v[0], v1=v[1], sum=0xc6ef3720, I; /* Set up/*
uint32_t delta=0x9e3779b9; /* A key schedule constant * *
uint32_t k0=k[0], k1=k[1], k2=k[2], k3=k[3]; /* Cache Key * *
For (i=0 i<32; i++) {/* Basic cycle start * *
V1-= ((v0<<4) + K2) ^ (v0 + sum) ^ ((v0>>5) + K3);
V0-= ((v1<<4) + k0) ^ (v1 + sum) ^ ((v1>>5) + K1);
Sum-= Delta;
}/* End cycle * *
V[0]=v0; V[1]=V1;
}