Answer the question
In order to leave comments, you need to log in
Is it possible to implement the TEA encryption method in PHP?
Hello, can you tell me if this algorithm can be rewritten in PHP?
Written in C:
void encrypt (uint32_t* v, uint32_t* k)
{
/* set up */
uint32_t v0 = v[0];
uint32_t v1 = v[1];
uint32_tsum = 0;
uint32_t i;
/* a key schedule constant */
uint32_t delta = 0x9e3779b9;
/* cache key */
uint32_t k0 = k[0];
uint32_t k1 = k[1];
uint32_t k2 = k[2];
uint32_t k3 = k[3];
/* basic cycle start */
for (i = 0; i < 32; i++)
{
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)
{
/* set up */
uint32_t v0 = v[0];
uint32_t v1 = v[1];
uint32_tsum = 0xC6EF3720;
uint32_t i;
/* a key schedule constant */
uint32_t delta = 0x9e3779b9;
/* cache key */
uint32_t k0 = k[0];
uint32_t k1 = k[1];
uint32_t k2 = k[2];
uint32_t k3 = k[3];
/* basic cycle start */
for (i = 0; i < 32; i++)
{
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;
}
Answer the question
In order to leave comments, you need to log in
Can. Here is an example implementation. In this case, a modification of the TEA algorithm is used.
XXTEA in PHP
Unfortunately, in its pure form, TEA is very vulnerable and it is not recommended to use it. In addition, I would recommend looking towards other encryption algorithms.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question