/*****************************************************************************/
/* MXTEA.JAVA  -  TEA Encryption Algorithm                                   */
/*                                                                           */
/* (C) Tdi GmbH                                                              */
/*                                                                           */
/* Implementation File for JAVA                                              */
/*****************************************************************************/
/* The Tiny Encryption Algorithm (TEA) by David Wheeler and Roger Needham of */
/* the Cambridge Computer Laboratory.                                        */
/* TEA is a Feistel cipher with XOR and and addition as the non-linear       */
/* mixing functions.                                                         */
/* Takes 64 bits (8 Bytes block) of data in Data[0] and Data[1].             */
/* Returns 64 bits of encrypted data in Data[0] and Data[1].                 */
/* Takes 128 bits of key in Key[0] - Key[3].                                 */
/*                                                                           */
/* In the calling routine, declare:                                          */
/*    int[] Key  = new int[4];                                               */
/*    int[] Data = new int[2];                                               */
/*                                                                           */
/* Then call the function:                                                   */
/*    MxTea.MxApp_Encrypt(Data, Key);                                        */
/*****************************************************************************/


import java.io.IOException;

public class MxTea
{

   public static short MxApp_Encrypt(int[] Data, int[] Key)
   {
      int   sum, delta;
      short cnt, i;
      
      delta = 0x9E3779B9;
      sum = 0;
      cnt = 32;
      
      for(i=1; i<=cnt; i++)
      {
         Data[0] = Data[0] + (((Data[1] << 4) ^ (Data[1] >>> 5)) + Data[1] ^ (sum + Key[sum & 3]));
         sum = sum + delta;
         Data[1] = Data[1] + (((Data[0] << 4) ^ (Data[0] >>> 5)) + Data[0] ^ (sum + Key[sum>>>11 & 3]));
      }
      return 0;
   }

}




