|
|||||||||
| Home >> All >> com >> ssttr >> [ crypto overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
com.ssttr.crypto
Class TEA

java.lang.Objectcom.ssttr.crypto.TEA
- All Implemented Interfaces:
- SKEncryption
- public class TEA
- extends java.lang.Object
- implements SKEncryption
- extends java.lang.Object
This is a 100% Pure Java implementation of the Tiny Encryption Algorithm which can be found http://vader.brad.ac.uk/tea/tea.shtml. Or at least that's where I originaly found it. It appears that it is still available here: http://www.simonshepherd.supanet.com/tea.htm.
TEA is only capable of using 128 bit keys. If any other key length is desired you will have to pad or chop (as appropriate) the key to be 128 bits long.
It was ported from the ANSI C new variant http://vader.brad.ac.uk/tea/source.shtml#new_ansi. As I mentioned above, that page seems to have disappeard, so here's the new equivelent: http://www.simonshepherd.supanet.com/source.htm#new_ansi. In case the original page goes down it's copied below:
Please feel free to use any of this code in your applications. The TEA algorithm (including new-variant TEA) has been placed in the public domain, as have my assembly language implementations.
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,
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(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,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;
}
| Field Summary | |
private int |
cycles
|
static int |
DEFAULT_ITERATIONS
Default number of iterations to perform durring encryption/decryption (32). |
private static int |
delta
|
private int[] |
key
|
private static int |
SUM
|
| Constructor Summary | |
TEA()
Creates a new instance of TEA |
|
TEA(int iterations)
Creates a new instance of TEA. |
|
| Method Summary | |
private void |
decipher(int[] in,
int[] out,
int offset)
|
byte[] |
decrypt(byte[] cryptedData)
Decrypts some data. |
private void |
encipher(int[] in,
int[] out,
int offset)
|
byte[] |
encrypt(byte[] rawData)
Encrypts some data. |
int |
getIterations()
|
void |
setHexKey(java.lang.String key)
Sets the encryption key to be used. |
void |
setKey(byte[] key)
Sets the encryption key to be used. |
private static byte[] |
toBytes(int[] ints)
|
private static int[] |
toInts(byte[] bytes)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
DEFAULT_ITERATIONS
public static final int DEFAULT_ITERATIONS
- Default number of iterations to perform durring encryption/decryption (32).
- See Also:
- Constant Field Values
key
private int[] key
delta
private static final int delta
- See Also:
- Constant Field Values
SUM
private static final int SUM
- See Also:
- Constant Field Values
cycles
private int cycles
| Constructor Detail |
TEA
public TEA()
- Creates a new instance of TEA
TEA
public TEA(int iterations)
- Creates a new instance of TEA.
| Method Detail |
getIterations
public int getIterations()
setHexKey
public void setHexKey(java.lang.String key)
- Sets the encryption key to be used.
setKey
public void setKey(byte[] key)
- Sets the encryption key to be used.
- Specified by:
setKeyin interfaceSKEncryption
encrypt
public byte[] encrypt(byte[] rawData)
- Encrypts some data.
- Specified by:
encryptin interfaceSKEncryption
decrypt
public byte[] decrypt(byte[] cryptedData)
- Decrypts some data.
- Specified by:
decryptin interfaceSKEncryption
encipher
private final void encipher(int[] in,
int[] out,
int offset)
decipher
private final void decipher(int[] in,
int[] out,
int offset)
toInts
private static int[] toInts(byte[] bytes)
toBytes
private static byte[] toBytes(int[] ints)
|
|||||||||
| Home >> All >> com >> ssttr >> [ crypto overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
com.ssttr.crypto.TEA