Hi,

I've chosen XXTEA (not XTEA but a derivate) for encryption and decryption of 
text. I made a PC program which generates the pdb file for my Palm app. I 
encrypt the text on the PC side and store the binary data in reverse order 
(last long as first, second last as second first..) and reverse the 4 byte long 
key. 

The PC app is written in Pascal. On the Palm side I use the code below to 
decrypt the text. My problem is that I'm not able to decrypt the text on my 
Palm. The decryption function reads beyond the data or starts at an odd 
address. I haven't done such a thing on the Pam before, I don't know what to do 
and I'd be glad for any help here. 

Benjamin

// That's what I use before calling the decryption function:
memoRecP = MemHandleLock (memoRecH);
noteLength = memoRecP->noteLength;
note = &memoRecP->keyn +4; 
note += StrLen (note) + 1;
offset = note - (Char*)memoRecP;
btea((long *) note, -32, (long *) key);  // <-- decrypt the note


// XXTEA encrytion and decryption fundtion. negative n = decryption. 
long btea( long * v, long n , long * k ) 
{
        unsigned long z=v[n-1], y=v[0], sum=0,e,
        DELTA=0x9e3779b9 ;
        long m, p, q ;

        if ( n>1) 
        {
                /* Coding Part */
                q = 6+52/n ;
                while ( q-- > 0 ) 
                {
                        sum += DELTA ;
                        e = sum >> 2&3 ;
                        for ( p = 0 ; p < n-1 ; p++ )
                                y = v[p+1],
                        z = v[p] += MX
                        y = v[0] ;
                        z = v[n-1] += MX
                }
                return 0 ; 
        }
        /* Decoding Part */
        else if ( n <-1 ) 
        {
                n = -n ;
                q = 6+52/n ;
                sum = q*DELTA ;
                while (sum != 0) 
                {
                        e = sum>>2 & 3 ;
                        for (p = n-1 ; p > 0 ; p-- )
                        z = v[p-1],
                        y = v[p] -= MX
                        z = v[n-1] ;
                        y = v[0] -= MX
                        sum -= DELTA ; 
                }
                return 0 ; 
        }
        
        return 1 ; 
} /* Signal n=0,1,-1 */

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please 
see http://www.palmos.com/dev/support/forums/

Reply via email to