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", password, charsmax(password));
// pack key
new i = 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 = EOS, len = 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(str, key);
// restore last char
str[len] = ch;
}
decrypt_string(str[]) {
new key[4] = get_password_key();
new ch = EOS, len = 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(str, key);
// restore last char
str[len] = ch;
}