Raised This Month: $32 Target: $400
 8% 

[INC] Tiny Encryption Algorithm


Post New Thread Reply   
 
Thread Tools Display Modes
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, 736 views)
File Type: inc xtea.inc (1.3 KB, 634 views)
__________________

Last edited by Zefir; 04-29-2011 at 16:08.
Zefir is offline
Send a message via ICQ to Zefir
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 12-16-2010 , 10:24   Re: [INC] Tiny Encryption Algorithm
Reply With Quote #2

Sounds nice, but in your example, you are encrypting and decrypting with two different keys, how's that supposed to work?
Seta00 is offline
Zefir
Member
Join Date: Oct 2007
Location: Kiev, Ukraine
Old 12-16-2010 , 11:20   Re: [INC] Tiny Encryption Algorithm
Reply With Quote #3

Why keys is different?
__________________
Zefir is offline
Send a message via ICQ to Zefir
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 12-16-2010 , 11:24   Re: [INC] Tiny Encryption Algorithm
Reply With Quote #4

Quote:
Originally Posted by Zefir View Post
Why keys is different?
lol nevermind, I thought create_key was actually creating the key, I just remembered it's actually packing a value.

But if you change password between a encrypt/decrypt operation, things will go wrong. Keys should be bound 1-to-1 with encrypted strings, not global values.
Seta00 is offline
Zefir
Member
Join Date: Oct 2007
Location: Kiev, Ukraine
Old 12-16-2010 , 11:40   Re: [INC] Tiny Encryption Algorithm
Reply With Quote #5

This is abstraction examples

In real plugin used global variables and some validators...
__________________
Zefir is offline
Send a message via ICQ to Zefir
xgam3r1
Junior Member
Join Date: Nov 2008
Old 12-18-2010 , 10:14   Re: [INC] Tiny Encryption Algorithm
Reply With Quote #6

you beat me to it, i have been working on an aio encryption include
xgam3r1 is offline
Old 12-18-2010, 12:31
lucas_7_94
This message has been deleted by lucas_7_94.
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 01-28-2011 , 12:50   Re: [INC] Tiny Encryption Algorithm
Reply With Quote #7

i made this

Code:
#include <amxmodx> #include <amxmisc> #include <xtea.inc> #define PLUGIN "New Plug-In" #define VERSION "1.0" #define AUTHOR "author" public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     register_clcmd("say /asd", "clcmd_asd") } public clcmd_asd(id) {     new szInfo[370], data[9]     new asd         client_print(id, print_chat, "%s" , xtea_crypt("asd", data))     client_print(id, print_chat, "called %s" , xtea_crypt_str("static-x", data))     }

but doesn't work , can any help me ?
__________________
ATWWMH - MiniDuels
Madness is like gravity, just need a little push.
lucas_7_94 is offline
Send a message via Skype™ to lucas_7_94
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 01-28-2011 , 19:42   Re: [INC] Tiny Encryption Algorithm
Reply With Quote #8

It doesn't return a value.

Code:
new key[4]; key = create_key(); new string[] = "asdf"; xtea_crypt_str(string, key); client_print(0, print_chat, "String: %s", string); xtea_decrypt_str(string, key); client_print(0, print_chat, "String: %s", string);
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 01-28-2011 , 20:37   Re: [INC] Tiny Encryption Algorithm
Reply With Quote #9

Quote:
Originally Posted by Exolent[jNr] View Post
It doesn't return a value.

Code:
new key[4]; key = create_key(); new string[] = "asdf"; xtea_crypt_str(string, key); client_print(0, print_chat, "String: %s", string); xtea_decrypt_str(string, key); client_print(0, print_chat, "String: %s", string);
i should go to test that NOW , thanks really thanks exolent.

I don't understand a one point , i should make these

Code:
create_key() { 
    new password[17], key[4]; 
    // get password string 
    get_cvar_string("password", password, charsmax(password)); 
    // pack key 
    new i = 0; 
    while (password[i] != EOS)  
        key{i} = password[i++] 

    return key 
}
and works ?
__________________
ATWWMH - MiniDuels
Madness is like gravity, just need a little push.

Last edited by lucas_7_94; 01-28-2011 at 20:41.
lucas_7_94 is offline
Send a message via Skype™ to lucas_7_94
AoD90
Senior Member
Join Date: Jul 2008
Location: Ugljevik/RS/BIH
Old 09-15-2011 , 12:06   Re: [INC] Tiny Encryption Algorithm
Reply With Quote #10

Can u make xxtea for amxx?

http://pear.php.net/package/Crypt_XX...XXTEA.php.html
AoD90 is offline
Send a message via MSN to AoD90
Reply



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 05:05.


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