Raised This Month: $ Target: $400
 0% 

[INC] Tiny Encryption Algorithm


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Zefir
Member
Join Date: Oct 2007
Location: Kiev, Ukraine
Old 12-16-2010 , 09:55   [INC] Tiny Encryption Algorithm
Reply With Quote #1

Tiny Encryption Algorithm (TEA).
Simple and fast symmetric-key algorithm cipher.

.: Description

Tiny Encryption Algorithm (TEA) is a block cipher notable for its simplicity of description and implementation, typically a few lines of code. It was designed by David Wheeler and Roger Needham of the Cambridge Computer Laboratory; it was first presented at the Fast Software Encryption workshop in Leuven in 1994, and first published in the proceedings of that workshop.

The cipher is not subject to any patents.

.: Links
Page of project
Official site
Wikipedia page

.: TEA

TEA operates on 64-bit blocks and uses a 128-bit key. Password must be declaration as pass[4], but string as array with 2 cell.

.: XTEA

Like TEA, XTEA is a 64-bit block Feistel network with a 128-bit key and a suggested 64 rounds. Several differences from TEA are apparent, including a somewhat more complex key-schedule and a rearrangement of the shifts, XORs, and additions.


.: Stocks
Length of the string must be even

stock tea_crypt_str(str[], key[4]) :
— crypt string with key
stock tea_decrypt_str(str[], key[4]) :
— decrypt string with key
stock tea_crypt(str[2], key[4]) :
— crypt 2 cell array with key
stock tea_decrypt(str[2], key[4]) :
— decrypt 2 cell array with key
stock xtea_crypt_str(str[], key[4]) :
— crypt string with key
stock xtea_decrypt_str(str[], key[4]) :
— decrypt string with key
stock xtea_crypt(str[2], key[4]) :
— crypt 2 cell array with key
stock xtea_decrypt(str[2], key[4]) :
— decrypt 2 cell array with key


.: Examples
Key creation

Key is composed from ordinary string of 16 characters length to packed array of 4 cell 4 bytes each.
PHP Code:
get_password_key() {
    new 
password[17], key[4];
    
// get password string
    
get_cvar_string("password"passwordcharsmax(password));
    
// pack key
    
new 0;
    while (
password[i] != EOS
        
key{i} = password[i++]

    return 
key

Prepare string to crypt

If length is not even last odd character is not encrypted
PHP Code:
crypt_string(str[]) {
    new 
key[4] = get_password_key();
    new 
ch EOSlen strlen(str);

    
// save last odd char
    
if (len 1)
        
ch str[--len];

    
// replace last char to the end of the string
    
str[len] = EOS;
    
xtea_crypt_string(strkey);
    
// restore last char
    
str[len] = ch;
}

decrypt_string(str[]) {
    new 
key[4] = get_password_key();
    new 
ch EOSlen strlen(str);
    
    
// save last odd char
    
if (len 1)
        
ch str[--len];

    
// replace last char to the end of the string
    
str[len] = EOS;
    
xtea_decrypt_string(strkey);
    
// restore last char
    
str[len] = ch;

Attached Files
File Type: inc tea.inc (1.4 KB, 756 views)
File Type: inc xtea.inc (1.3 KB, 653 views)
__________________

Last edited by Zefir; 04-29-2011 at 16:08.
Zefir is offline
Send a message via ICQ to Zefir
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 13:36.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode