-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathxxtea.c
55 lines (47 loc) · 1.64 KB
/
xxtea.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/***********************************************************************
Copyright 2006-2009 Ma Bingyao
Copyright 2013 Gao Chunhui, Liu Tao
These sources is free software. Redistributions of source code must
retain the above copyright notice. Redistributions in binary form
must reproduce the above copyright notice. You can redistribute it
freely. You can use it with any free or commercial software.
These sources is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY. Without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
github: https://github.com/liut/pecl-xxtea
*************************************************************************/
#include "xxtea.h"
void xxtea_long_encrypt(xxtea_long *v, xxtea_long len, xxtea_long *k) {
xxtea_long n = len - 1;
xxtea_long z = v[n], y = v[0], p, q = 6 + 52 / (n + 1), sum = 0, e;
if (n < 1) {
return;
}
while (0 < q--) {
sum += XXTEA_DELTA;
e = sum >> 2 & 3;
for (p = 0; p < n; p++) {
y = v[p + 1];
z = v[p] += XXTEA_MX;
}
y = v[0];
z = v[n] += XXTEA_MX;
}
}
void xxtea_long_decrypt(xxtea_long *v, xxtea_long len, xxtea_long *k) {
xxtea_long n = len - 1;
xxtea_long z = v[n], y = v[0], p, q = 6 + 52 / (n + 1), sum = q * XXTEA_DELTA, e;
if (n < 1) {
return;
}
while (sum != 0) {
e = sum >> 2 & 3;
for (p = n; p > 0; p--) {
z = v[p - 1];
y = v[p] -= XXTEA_MX;
}
z = v[n];
y = v[0] -= XXTEA_MX;
sum -= XXTEA_DELTA;
}
}