C Implementation of Tea Algorithm

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.