efficient implementation of Tiny Encryption Algorithm (TEA)
From: Tom (virat1208_at_yahoo.co.in)
Date: 04/20/04
- Next message: Guy Macon: "Re: JBN users busted by NSA, proving NSA blows your privacy"
- Previous message: Pascal Junod: "Re: Approximating random S-box differentials"
- Next in thread: Tom St Denis: "Re: efficient implementation of Tiny Encryption Algorithm (TEA)"
- Reply: Tom St Denis: "Re: efficient implementation of Tiny Encryption Algorithm (TEA)"
- Reply: Mark VandeWettering: "Re: efficient implementation of Tiny Encryption Algorithm (TEA)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: 20 Apr 2004 01:06:38 -0700
Hi,
I am a graduate student doing research in the area of cryptography. I
have just started on my PhD and I need urgent help. I have coded both
tea and xtea (an improved version of tea) in C++ and my code is as
below (I am using Borland Turbo C++ 3.0).
1. I need to know if my implementations can be furthur optimized, so
as to reduce execution time and memory requirements.
2. I also need to know if my data and key entry as well as output
methods are suited for this.
3. how to encrypt strings using this
I shall be highly obliged to anyone who helps me with this.
Virat
-----------tea--------------------
# include <stdio.h>
# include <stdlib.h>
# include <iostream.h>
int main ()
{void code(long s[], long t[]);
void decode(long s[], long t[]);
long v[2],k[4];
int i,j;
for(i=0;i<2;i++)
{cout<<"enter a value";
cin>>v[i];
}
for(j=0;j<4;j++)
{cout<<"enter a key";
cin>>k[j];
}
for (int a=0; a<100; a++)
{
code(v,k);
for (int g=0;g<2;g++)
{cout<<v[g]<<"\n";
}
decode(v,k);
for(int h=0; h<2; h++)
{cout<<v[h]<<"\n";
}
}
return 0;
}
void code(long* s, long* t) {
unsigned long y=s[0],z=s[1], sum=0, delta=0x9e3779b9, n=32 ;
while (n-->0) {
sum += delta ;
y += ((z<<4)+t[0] ^ (z+sum) ^ (z>>5)+t[1]) ;
z += ((y<<4)+t[2] ^ (y+sum) ^ (y>>5)+t[3]) ;
}
s[0]=y ;
s[1]=z ;
}
void decode(long* s, long* t) {
unsigned long n=32, sum, y=s[0], z=s[1], delta=0x9e3779b9;
sum=delta<<5;
while (n-->0) {
z -= ((y<<4)+t[2] ^ (y+sum) ^ (y>>5)+t[3]) ;
y -= ((z<<4)+t[0] ^ (z+sum) ^ (z>>5)+t[1]) ;
sum -= delta ;}
s[0]=y; s[1]=z; }
----------xtea------------------
# include <stdio.h>
# include <stdlib.h>
# include <iostream.h>
int main ()
{void tean(long s[], long t[], long n);
void decode(long s[], long t[], long n);
long v[2],k[4];
int p;
for(int i=0;i<2;i++)
{cout<<"enter 2 values";
cin>>v[i];
}
for(int j=0;j<4;j++)
{cout<<"enter a key";
cin>>k[j];
}
cout<<"enter p";
cin>>p;
if (p>0)
{
tean(v,k,p);
for (int g=0;g<2;g++)
{cout<<v[g]<<"\n";
}
}
else
{
decode(v,k,p);
for(int l=0; l<2; l++)
{cout<<v[l]<<"\n";
}
}
return 0;
}
void tean(long* s, long* t, long n) {
unsigned long y=s[0],z=s[1], delta=0x9e3779b9;
if (n>0) {
unsigned long limit=delta*n, sum=0;
while (sum!=limit)
y += (z<<4 ^ z>>5) + z^sum + t[sum&3],
sum += delta,
z += (y<<4 ^ y>>5) + y^sum + t[sum>>11&3];
}
s[0]=y, s[1]=z ;
}
void decode(long* s, long* t, long n) {
unsigned long y=s[0],z=s[1], delta=0x9e3779b9, sum=delta*(-n);
if (n<0) {
while (sum)
z -= (y<<4 ^ y>>5) + y^sum + t[sum>>11&3],
sum -= delta,
y -= (z<<4 ^ z>>5) + z^sum + t[sum&3];
}
s[0]=y, s[1]=z ;
}
- Next message: Guy Macon: "Re: JBN users busted by NSA, proving NSA blows your privacy"
- Previous message: Pascal Junod: "Re: Approximating random S-box differentials"
- Next in thread: Tom St Denis: "Re: efficient implementation of Tiny Encryption Algorithm (TEA)"
- Reply: Tom St Denis: "Re: efficient implementation of Tiny Encryption Algorithm (TEA)"
- Reply: Mark VandeWettering: "Re: efficient implementation of Tiny Encryption Algorithm (TEA)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|