Share Tips, Code Samples, etc. with the Visual Prolog community.
Chan Bok
Active Member
Posts: 26
Joined: 13 Sep 2000 23:01

Tiny Encryption Algorithm (TEA)

The c codes for TEA (from Wikipedia) are as follows:

Code: Select all

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 < 32; 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; }

Code: Select all

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; }
======================================================================

The following is an implementation of TEA using VIP7.3(CE):

Code: Select all