Java/J2ME Trivial Encryption Algorithm (TEA) implementation

Java/J2ME implementation of the Tiny Encryption Algorithm

The Tiny Encryption Algorithm (TEA) is a fast, simple and robust block cipher designed by David Wheeler and Roger Needham. This code is released under the LGPL. The algorithm is implemented in a single class: It is designed to work with J2ME (a cut-down java for mobile devices).

There are some theoretical problems with TEA and it has been superceded by XXTEA. See the wikipedia page reference above for the grisly details.

Getting the software

Two files are available:


The TEA class is simple to use:

    // Initialize a TEA cipher using the first 16 bytes of a passphrase
    TEA tea = new TEA("And is there honey still for tea?".getBytes());
    // Then use it to encrypt clear text...
    byte[] ciphertext = tea.encrypt("This is the text to encrypt".getBytes());
    // ...or decrypt a ciphertext
    byte[] cleartext = tea.decrypt(ciphertext);
Or if you want a string:
    String cleartext = new String(tea.decrypt(ciphertext));


Please report bugs to


Although this code is probably too trifiling to argue over, for the avoidance of doubt and encouragement of comments/contributions it is published under the LGPL.