Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Serious, but bizarre issues with this alg

Status
Not open for further replies.

AskTom

Programmer
Joined
Jun 8, 2005
Messages
2
Location
GB
I have some issues with this algorithm, it's TEA. Sometimes it decrypts fine, and others it doesn't. I have tested and tested, and thought hard, but canot seem to see where the problem lies.

The strings, are 32bits, I have escaped, unescaped, all sorts, but nothing makes it work perfect.

So, for example, 8 a's makes it fail, but nine doesn;t.
Or, eight mixed characters, makes it work.

Can someone please tell me what is going on here.
function encrypt(mess,key)
{
while (mess.length%4!=0) {mess+=0;}
arr1=strToLong(mess);
while (key.length<20) {key+=key;}
var keyst=key.substr(0,16);
key1=strToLong(keyst);
delta=0x9E3779B9;
sum=0x00000000;
n=16;

if (arr1.length==0) {return '';}
if (arr1.length==1) {arr1[i++]=0;}

while (n-->0)
{
sum+=delta;
for (var i=0;i<arr1.length-1;i++)
{
arr1+=((arr1[i+1]<<4)+key1[0])^(sum+arr1[i+1])^((arr1[i+1]>>>5)+key1[1]);
arr1[i+1]+=((arr1<<4)+key1[2])^(sum+arr1)^((arr1>>>5)+key1[3]);
}

}
var dum=longToStr(arr1);
document.all.len.value=mess.length;
return dum;

}

function decrypt(mess,key)
{
arr1=strToLong(mess);
while (key.length<20) {key+=key;}
var keyst=key.substr(0,16);
key1=strToLong(keyst);
delta=0x9E3779B9;
sum=delta<<4;
n=16;

if (arr1.length==0) {return '';}

while (n-->0)
{
for (var i=arr1.length-2;i>=0;i--)
{
arr1[i+1]-=(((arr1<<4)+key1[2])^(sum+arr1)^((arr1>>>5)+key1[3]));
arr1-=(((arr1[i+1]<<4)+key1[0])^(sum+arr1[i+1])^((arr1[i+1]>>>5)+key1[1]));
}

sum-=delta;
}
var dum=longToStr(arr1);
if (dum.indexOf('0')>-1) {dum=dum.substr(0,dum.indexOf('0'));}
return dum;

}

 
Whick part fails, and with what error?


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Ok.

The algorithm works normally for most of the time. However, there is a mistake, and there is no pattern to the mistake. So I gave the example, 7 a's fine, 8 a's not working, 9 a's works fine again.

Also, the sentance, 'The notion of multiplication.' Does not work, (ie encrypt and decrypt to the same), but the sentance 'The notion of mulitplication.' does work.

I hope you see that there is a slight, but only slight difference there, but it makes enough difference to make it work.

There doesn't appear to be a patternation for the errors, and I am unsure where to go now.

But thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top