Class XTEA

  • All Implemented Interfaces:
    BlockCipher

    public class XTEA
    extends java.lang.Object
    implements BlockCipher
    An implementation of the XTEA block cipher algorithm.

    This implementation uses 32 rounds. The best attack reported as of 2009 is 36 rounds (Wikipedia).

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static int DELTA  
      private int k0  
      private int k1  
      private int k10  
      private int k11  
      private int k12  
      private int k13  
      private int k14  
      private int k15  
      private int k16  
      private int k17  
      private int k18  
      private int k19  
      private int k2  
      private int k20  
      private int k21  
      private int k22  
      private int k23  
      private int k24  
      private int k25  
      private int k26  
      private int k27  
      private int k28  
      private int k29  
      private int k3  
      private int k30  
      private int k31  
      private int k4  
      private int k5  
      private int k6  
      private int k7  
      private int k8  
      private int k9  
    • Constructor Summary

      Constructors 
      Constructor Description
      XTEA()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void decrypt​(byte[] bytes, int off, int len)
      Decrypt a number of bytes.
      private void decryptBlock​(byte[] in, byte[] out, int off)  
      void encrypt​(byte[] bytes, int off, int len)
      Encrypt a number of bytes.
      private void encryptBlock​(byte[] in, byte[] out, int off)  
      int getKeyLength()
      Get the length of the key in bytes.
      void setKey​(byte[] b)
      Set the encryption key used for encrypting and decrypting.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • k0

        private int k0
      • k1

        private int k1
      • k2

        private int k2
      • k3

        private int k3
      • k4

        private int k4
      • k5

        private int k5
      • k6

        private int k6
      • k7

        private int k7
      • k8

        private int k8
      • k9

        private int k9
      • k10

        private int k10
      • k11

        private int k11
      • k12

        private int k12
      • k13

        private int k13
      • k14

        private int k14
      • k15

        private int k15
      • k16

        private int k16
      • k17

        private int k17
      • k18

        private int k18
      • k19

        private int k19
      • k20

        private int k20
      • k21

        private int k21
      • k22

        private int k22
      • k23

        private int k23
      • k24

        private int k24
      • k25

        private int k25
      • k26

        private int k26
      • k27

        private int k27
      • k28

        private int k28
      • k29

        private int k29
      • k30

        private int k30
      • k31

        private int k31
    • Constructor Detail

      • XTEA

        public XTEA()
    • Method Detail

      • setKey

        public void setKey​(byte[] b)
        Description copied from interface: BlockCipher
        Set the encryption key used for encrypting and decrypting. The key needs to be 16 bytes long.
        Specified by:
        setKey in interface BlockCipher
        Parameters:
        b - the key
      • encrypt

        public void encrypt​(byte[] bytes,
                            int off,
                            int len)
        Description copied from interface: BlockCipher
        Encrypt a number of bytes. This is done in-place, that means the bytes are overwritten.
        Specified by:
        encrypt in interface BlockCipher
        Parameters:
        bytes - the byte array
        off - the start index
        len - the number of bytes to encrypt
      • decrypt

        public void decrypt​(byte[] bytes,
                            int off,
                            int len)
        Description copied from interface: BlockCipher
        Decrypt a number of bytes. This is done in-place, that means the bytes are overwritten.
        Specified by:
        decrypt in interface BlockCipher
        Parameters:
        bytes - the byte array
        off - the start index
        len - the number of bytes to decrypt
      • encryptBlock

        private void encryptBlock​(byte[] in,
                                  byte[] out,
                                  int off)
      • decryptBlock

        private void decryptBlock​(byte[] in,
                                  byte[] out,
                                  int off)
      • getKeyLength

        public int getKeyLength()
        Description copied from interface: BlockCipher
        Get the length of the key in bytes.
        Specified by:
        getKeyLength in interface BlockCipher
        Returns:
        the length of the key