Microsoft Store
 

Tiny Encryption Algorithm


 

:This article is about the TEA encryption algorithm. For other meanings, see TEA (disambiguation).

Reference code

Following is an adaptation of the reference encryption and decryption routines in C, released into the public domain by David Wheeler and Roger Needham:

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

void encrypt(unsigned long* v, unsigned long* k) {

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

unsigned long v0=v, v1=v, sum=0, i; /* set up */

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

unsigned long delta=0x9e3779b9; /* a key schedule constant */

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

unsigned long k0=k, k1=k, k2=k, k3=k; /* cache key */

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

for (i=0; i < 32; i++) { /* basic cycle start */

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

sum += delta;

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

v0 += (v15)+k1;

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

v1 += (v05)+k3; /* end cycle */

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

}

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

v=v0; v=v1;

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

}

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

void decrypt(unsigned long* v, unsigned long* k) {

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

unsigned long v0=v, v1=v, sum=0xC6EF3720, i; /* set up */

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

unsigned long delta=0x9e3779b9; /* a key schedule constant */

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

unsigned long k0=k, k1=k, k2=k, k3=k; /* cache key */

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

for(i=0; i

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

v1 -= (v0 > 5)+k3;

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

v0 -= (v1 > 5)+k1;

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

sum -= delta; /* end cycle */

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

}

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

v=v0; v=v1;

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

}

~ ~ ~ ~ ~ ~ ~ ~ ~ ~

~ Table of Content ~

Introduction
Properties
Reference code
References
External links

 

 

~ What's Hot ~


~ Community ~

History Forum
Come and discuss about History, Civilizations, Historical Events and Figures
History Web-Ring
A community of sites, blogs and forums dedicated to History. Do not hesitate to submit your site.