The discussion on tea, xtea, and xxtea on the Internet is very enthusiastic, and the implementation of PHP, JSP, ASP, and C # is provided.
TeaAlgorithmIt is famous for its speed. Compared with C, the implementation of C is short.
Here is the implementation of C:
// 0 × 9e3779b9 is always inseparable from us. Even here, it will appear again !!! // Look, it comes again. That 0x9e3779b9 is the golden split that always appears in our lives !!! // Tiny Encryption Algorithm // The Standard 32-round tea is attacked. We recommend that you use the tea version xxtea. // Note that V is 64bit, and K is 128bit. Do not use an error. Void Tea_encrypt (unsignedLong * V, unsigned Long * K) {unsigned Long V0 = V [ 0 ], V1 = V [ 1 ], Sum = 0 , I; unsigned Long Delta = 0 ×9e3779b9; unsigned Long K0 = K [ 0 ], K1 = K [1 ], K2 = K [ 2 ], K3 = K [ 3 ]; For (I = 0 ; I < 32 ; I ++ ) {Sum + = Delta; V0 + = (V1 < 4 ) + K0) ^ (V1 + sum) ^ (V1> 5 ) + K1); V1 + = (V0 <4 ) + K2) ^ (v0 + sum) ^ (v0> 5 ) + K3);} V [ 0 ] = V0; V [ 1 ] = V1 ;} Void Tea_decrypt (unsigned Long * V, unsigned Long * K) {unsigned Long V0 = V [ 0 ], V1 = V [ 1 ], Sum =0xc6ef3720 , I; unsigned Long Delta = 0 ×9e3779b9; unsigned Long K0 = K [ 0 ], K1 = K [ 1 ], K2 = K [ 2 ], K3 = K [ 3 ]; For (I = 0 ; I < 32 ; I ++) {V1 -= (V0 < 4 ) + K2) ^ (v0 + sum) ^ (v0> 5 ) + K3); V0 -= (V1 < 4 ) + K0) ^ (V1 + sum) ^ (V1> 5 ) + K1); sum -= Delta;} V [ 0 ] = V0; V [ 1 ] = V1 ;}
The C Implementation of Tiny Encryption Algorithm is too short and easy to understand.
However, when using it, you must note that it already has an attack algorithm.
If you like Pascal or Delphi implementation, you can go to this link to find:
There are tea, xtea, xxtea, and blocktea implementations. Comprehensive.
Http://www.shokhirev.com/nikolai/programs/code/Cryptography/uTeaSet_pas.html