encrypting a string in C using XTEA

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • goron
    New Member
    • Sep 2007
    • 4

    encrypting a string in C using XTEA

    Hello,

    I'm trying to encrypt the final output of my program. This final output is a char buffer, a string, the encrypted form of which I'd like to save to a text file. I have the XTEA code working, but I'm not sure how to use it with a string rather than a long int. Here's the XTEA code, for reference:

    Code:
    void encipher(const unsigned long *const v,unsigned long *const w,
       const unsigned long * const k)
    {
       register unsigned long       y=v[0],z=v[1],sum=0,delta=0x9E3779B9,n=32;
    
       while(n-->0)
          {
          y += (z << 4 ^ z >> 5) + z ^ sum + k[sum&3];
          sum += delta;
          z += (y << 4 ^ y >> 5) + y ^ sum + k[sum>>11 & 3];
          }
    
       w[0]=y; w[1]=z;
    }
    
    void decipher(const unsigned long *const v,unsigned long *const w,
       const unsigned long * const k)
    {
       register unsigned long       y=v[0],z=v[1],sum=0xC6EF3720,
    				delta=0x9E3779B9,n=32;
    
       /* sum = delta<<5, in general sum = delta * n */
    
       while(n-->0)
          {
          z -= (y << 4 ^ y >> 5) + y ^ sum + k[sum>>11 & 3];
          sum -= delta;
          y -= (z << 4 ^ z >> 5) + z ^ sum + k[sum&3];
          }
       
       w[0]=y; w[1]=z;
    }
    Thanks in advance.
Working...