Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
06/03/05 20:04
Read: times


 
#94320 - Here it is
Responding to: ???'s previous message
Vignesh here is the code
v is the data to be encrypted (0x12345678)
w is the resulted encrypted data, so after calling decipher();
w = 0x12345678.
k is the key.
If you try this on a PC compiler it should work w/o a problem.

Thanks



void encipher(unsigned long *v,unsigned long *w, 
const unsigned long * const k);
void decipher(unsigned long *v,unsigned long *w, 
unsigned long * k);
    
unsigned long v = 0x12345678;
unsigned long w = 0;
unsigned long k = 0x7364e829 ; 
//unsigned long x = 0;
void Main(void)
{
  unsigned long v = 0x12345678;
  //unsigned long x = 0;
//  printf ("%xn", v);

  encipher(&v, &w, &k);  // (0x12345678) 
  decipher(&w, &w, &k);  // (0x12345678)   
//  printf ("%xn", x);
  while (1)
  {
   PCON |= 0x00;
  }
}
  
void encipher(unsigned long *v,unsigned long *w, 
const unsigned long * const k)
{ 
   register unsigned long       y=v[0],z=v[1],sum=0,delta=0x9E3779B9, 
    a=k[0],b=k[1],c=k[2],d=k[3],n=32; 
   while(n-->0) 
      { 
      sum += delta; 
      y += (z << 4)+a ^ z+sum ^ (z >> 5)+b; 
      z += (y << 4)+c ^ y+sum ^ (y >> 5)+d; 
      } 

   w[0]=y; w[1]=z; 
} 
  
void decipher(unsigned long *v,unsigned long *w, 
unsigned long * k)
{ 
   register unsigned long       y=v[0],z=v[1],sum=0xC6EF3720, 
    delta=0x9E3779B9,a=k[0],b=k[1], 
    c=k[2],d=k[3],n=32; 
   /* sum = delta<<5, in general sum = delta * n */ 

   while(n-->0) 
      { 
      z -= (y << 4)+c ^ y+sum ^ (y >> 5)+d; 
      y -= (z << 4)+a ^ z+sum ^ (z >> 5)+b; 
      sum -= delta; 
      } 
    
   w[0]=y; w[1]=z; 
}


List of 30 messages in thread
TopicAuthorDate
TEA            01/01/70 00:00      
   Endianess            01/01/70 00:00      
      Any recommendations?            01/01/70 00:00      
         Assess your requirements            01/01/70 00:00      
         Test vectors            01/01/70 00:00      
      platform-dependent            01/01/70 00:00      
   Why TEA?            01/01/70 00:00      
      Did you Mean DES            01/01/70 00:00      
         Yes, DES            01/01/70 00:00      
            Here it is            01/01/70 00:00      
               It would be better            01/01/70 00:00      
                  Go here!            01/01/70 00:00      
               And what is your result?            01/01/70 00:00      
                  Not right?            01/01/70 00:00      
                     I expected that...            01/01/70 00:00      
                        Here are the results I am gettng            01/01/70 00:00      
                           Michael is right:            01/01/70 00:00      
                              MS Visual C.            01/01/70 00:00      
                           Recipe for success            01/01/70 00:00      
                              problem with "standard implementation"..            01/01/70 00:00      
                                 Example for the user            01/01/70 00:00      
                                    like this?            01/01/70 00:00      
                                       What else?            01/01/70 00:00      
                                          ???            01/01/70 00:00      
                                             I noticed that            01/01/70 00:00      
                                       Statics init to zero            01/01/70 00:00      
               Code Problems            01/01/70 00:00      
   Didn't search first?            01/01/70 00:00      
   It's easy?            01/01/70 00:00      
      Useful fast shift and roll functions            01/01/70 00:00      

Back to Subject List