Java Doc for TEA.java in  » Web-Mail » jwebmail-0.7 » net » wastl » webmail » misc » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Mail » jwebmail 0.7 » net.wastl.webmail.misc 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   net.wastl.webmail.misc.TEA

TEA
public class TEA (Code)
Tiny Encryption Algorithm.

(The following description is from the web page for the C and Assembler source code at University of Bradford Yorkshire, England - The Cryptography & Computer Communications Security Group) The description is used with the permission of the authors, Dr S J Shepherd and D A G Gillies.

The Tiny Encryption Algorithm is one of the fastest and most efficient cryptographic algorithms in existence. It was developed by David Wheeler and Roger Needham at the Computer Laboratory of Cambridge University. It is a Feistel cipher which uses operations from mixed (orthogonal) algebraic groups - XORs and additions in this case. It encrypts 64 data bits at a time using a 128-bit key. It seems highly resistant to differential cryptanalysis, and achieves complete diffusion (where a one bit difference in the plaintext will cause approximately 32 bit differences in the ciphertext) after only six rounds. Performance on a modern desktop computer or workstation is very impressive.

TEA takes 64 bits of data in v[0] and v[1], and 128 bits of key in k[0] - k[3]. The result is returned in w[0] and w[1]. Returning the result separately makes implementation of cipher modes other than Electronic Code Book a little bit easier.

TEA can be operated in any of the modes of DES.

n is the number of iterations. 32 is ample, 16 is sufficient, as few as eight should be OK for most applications, especially ones where the data age quickly (real-time video, for example). The algorithm achieves good dispersion after six iterations. The iteration count can be made variable if required.

Note this algorithm is optimised for 32-bit CPUs with fast shift capabilities. It can very easily be ported to assembly language on most CPUs.

delta is chosen to be the Golden ratio ((5/4)1/2 - 1/2 ~ 0.618034) multiplied by 232. On entry to decipher(), sum is set to be delta * n. Which way round you call the functions is arbitrary: DK(EK(P)) = EK(DK(P)) where EK and DK are encryption and decryption under key K respectively.

Translator's notes:

  • Although the this algorithm is optimised for 32-bit CPUs with fast shift capabilities Java manages to throw it all away by not providing unsigned values resulting in the excessive use of AND's to prevent sign extension on promotion of a byte to an integer.
  • The following description is taken from the Mach5 Software cryptography archives at www.mach5.com/crypto.

    Tiny Encryption Algorithm (TEA)
    TEA is a cryptographic algorithm designed to minimize memory footprint, and maximize speed. However, the cryptographers from Counterpane Systems have discovered three related-key attacks on TEA, the best of which requires only 223 chosen plaintexts and one related key query. The problems arise from the overly simple key schedule. Each TEA key can be found to have three other equivalent keys, as described in a paper by David Wagner, John Kelsey, and Bruce Schneier. This precludes the possibility of using TEA as a hash function. Roger Needham and David Wheeler have proposed extensions to TEA that counters the above attacks.

Example of use:

 byte key[] = new BigInteger("39e858f86df9b909a8c87cb8d9ad599", 16).toByteArray();
 TEA t = new TEA(key);
 
String src = "hello world!"; System.out.println("input = " + src); byte plainSource[] = src.getBytes(); int enc[] = t.encode(plainSource, plainSource.length); System.out.println(t.padding() + " bytes added as padding."); byte dec[] = t.decode(enc); System.out.println("output = " + new String(dec));

author:
   Translated by Michael Lecuyer (mjl@theorem.com) from the C Language.
version:
   1.0 Sep 8, 1998
since:
   JDK1.1



Constructor Summary
public  TEA(byte key)
     Accepts key for enciphering/deciphering.

Method Summary
public  int[]decipher(int v)
     Decipher two ints.
public  byte[]decipher(byte v)
     Decipher two bytess.
public  byte[]decode(byte b, int count)
     Convert a byte array to ints and then decode.
public  byte[]decode(int b)
     Decode an integer array.
public  int[]encipher(int v)
     Encipher two ints. Replaces the original contents of the parameters with the results. The integers are usually created from 8 bytes. The usual way to collect bytes to the int array is:
 byte ba[] = { ....
public  byte[]encipher(byte v)
     Encipher two bytess.
 int[]encode(byte b, int count)
     Byte wrapper for encoding.
public static  voidmain(String args)
     Encodes and decodes "Hello world!" for your personal pleasure.
public  intpadding()
     Report how much padding was done in the last encode.
public  StringtoString()
    


Constructor Detail
TEA
public TEA(byte key)(Code)
Accepts key for enciphering/deciphering.
throws:
  ArrayIndexOutOfBoundsException - if the key isn't the correct length.
Parameters:
  key - 128 bit (16 byte) key.




Method Detail
decipher
public int[] decipher(int v)(Code)
Decipher two ints. Replaces the original contents of the parameters with the results. The integers are usually decocted to 8 bytes. The decoction of the ints to bytes can be done this way.
 int x[] = decipher(ins);
 outb[j]   = (byte)(x[0] >>> 24);
 outb[j+1] = (byte)(x[0] >>> 16);
 outb[j+2] = (byte)(x[0] >>> 8);
 outb[j+3] = (byte)(x[0]);
 outb[j+4] = (byte)(x[1] >>> 24);
 outb[j+5] = (byte)(x[1] >>> 16);
 outb[j+6] = (byte)(x[1] >>> 8);
 outb[j+7] = (byte)(x[1]);
 

Parameters:
  v - int array of 2 deciphered int array of 2



decipher
public byte[] decipher(byte v)(Code)
Decipher two bytess.
Parameters:
  v - byte array of 2 decipherd byte array of 2



decode
public byte[] decode(byte b, int count)(Code)
Convert a byte array to ints and then decode. There may be some padding at the end of the byte array from the previous encode operation.
Parameters:
  b - bytes to decode
Parameters:
  count - number of bytes in the array to decode byte array of decoded bytes.



decode
public byte[] decode(int b)(Code)
Decode an integer array. There may be some padding at the end of the byte array from the previous encode operation.
Parameters:
  b - bytes to decode
Parameters:
  count - number of bytes in the array to decode byte array of decoded bytes.



encipher
public int[] encipher(int v)(Code)
Encipher two ints. Replaces the original contents of the parameters with the results. The integers are usually created from 8 bytes. The usual way to collect bytes to the int array is:
 byte ba[] = { .... };
 int v[] = new int[2];
 v[0] = (ba[j] << 24 ) | (((ba[j+1])&0xff) << 16) | (((ba[j+2])&0xff) << 8) | ((ba[j+3])&0xff);
 v[1] = (ba[j+4] << 24 ) | (((ba[j+5])&0xff) << 16) | (((ba[j+6])&0xff) << 8) | ((ba[j+7])&0xff);
 v = encipher(v);
 

Parameters:
  v - two int array as input. array of two ints, enciphered.



encipher
public byte[] encipher(byte v)(Code)
Encipher two bytess.
Parameters:
  v - byte array of 2 enciphered byte array of 2



encode
int[] encode(byte b, int count)(Code)
Byte wrapper for encoding. Converts bytes to ints. Padding will be added if required.
Parameters:
  b - incoming byte array byte count integer conversion array, possibly with padding.
See Also:   TEA.padding



main
public static void main(String args)(Code)
Encodes and decodes "Hello world!" for your personal pleasure.



padding
public int padding()(Code)
Report how much padding was done in the last encode. bytes of padding added
See Also:   TEA.encode



toString
public String toString()(Code)
Representation of TEA class



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.