AMXX-BG.INFO xtea.inc Raw include

xtea.inc

Original include source with line numbers.

Back Download .inc
1 /*
2 Extenshion of Tiny Encryption Algorithm
3 from http://143.53.36.235:8080/tea.htm
4 or http://en.wikipedia.org/wiki/Tiny_Encryption_Algorithm
5
6 developed for Cerberus project
7 by Zefir<[email protected]>
8 http://up.org.ua/
9 xmpp://[email protected]/
10 http://cerberus.cstrike.in.ua/
11
12 13 december 2010 (c) Zefir
13 */
14
15 #if defined _xtea_included
16 #endinput
17 #endif
18 #define _xtea_included
19
20
21 stock xtea_crypt_str(str[], key[4]) {
22 new len = strlen(str);
23 if (len & 1)
24 set_fail_state("Length of the string for tea_crypt_str() must be even")
25
26 while (len > 0)
27 xtea_crypt(str[len -= 2], key);
28 }
29
30 stock xtea_decrypt_str(str[], key[4]) {
31 new len = strlen(str);
32 if (len & 1)
33 set_fail_state("Length of the string for tea_decrypt_str() must be even")
34
35 while (len > 0)
36 xtea_decrypt(str[len -= 2], key);
37 }
38
39 stock xtea_crypt(str[], key[4]) {
40 new y = str[0], z = str[1], sum = 0,
41 delta = 0x9e3779b9, n = 32;
42
43 while (n-- > 0) {
44 y += (z << 4 ^ z >>> 5) + z ^ sum + key[sum & 3];
45 sum += delta;
46 z += (y << 4 ^ y >>> 5) + y ^ sum + key[sum >>> 11 & 3];
47 }
48
49 str[0] = y; str[1] = z;
50 }
51
52 stock xtea_decrypt(str[], key[4]) {
53 new y = str[0], z = str[1], sum = 0xC6EF3720,
54 delta = 0x9e3779b9, n = 32;
55
56 while (n-- > 0) {
57 z -= (y << 4 ^ y >>> 5) + y ^ sum + key[sum >>> 11 & 3];
58 sum -= delta;
59 y -= (z << 4 ^ z >>> 5) + z ^ sum + key[sum & 3];
60 }
61
62 str[0] = y; str[1] = z;
63 }
64