AMXX-BG.INFO tea.inc Raw include

tea.inc

Original include source with line numbers.

Back Download .inc
1 /*
2 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 _tea_included
16 #endinput
17 #endif
18 #define _tea_included
19
20
21 stock tea_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 tea_crypt(str[len -= 2], key);
28 }
29
30 stock tea_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 tea_decrypt(str[len -= 2], key);
37 }
38
39 stock tea_crypt(str[], key[4]) {
40 new y = str[0], z = str[1], sum = 0,
41 delta = 0x9e3779b9, n = 32;
42
43 new k0 = key[0], k1 = key[1], k2 = key[2], k3 = key[3];
44
45 while (n-- > 0) {
46 sum += delta;
47 y += ((z << 4) + k0) ^ (z + sum ^ (z >>> 5) + k1);
48 z += ((y << 4) + k2) ^ (y + sum ^ (y >>> 5) + k3);
49 }
50
51 str[0] = y; str[1] = z;
52 }
53
54 stock tea_decrypt(str[], key[4]) {
55 new y = str[0], z = str[1], sum = 0xC6EF3720,
56 delta = 0x9e3779b9, n = 32;
57
58 new k0 = key[0], k1 = key[1], k2 = key[2], k3 = key[3];
59
60 while (n-- > 0) {
61 z -= ((y << 4) + k2) ^ (y + sum) ^ ((y >>> 5) + k3);
62 y -= ((z << 4) + k0) ^ (z + sum) ^ ((z >>> 5) + k1);
63 sum -= delta;
64 }
65
66 str[0] = y; str[1] = z;
67 }
68