-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.c
55 lines (45 loc) · 1.25 KB
/
test.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
/*
* test.c
*
* copyright (c) 2019 Xiongfei Shi
*
* author: Xiongfei Shi <jenson.shixf(a)gmail.com>
* license: Apache2.0
*
* https://github.com/shixiongfei/xtea
*/
#include <stdio.h>
#include <string.h>
#include "xtea.h"
int main(int argc, char *argv[]) {
const char text[] = { "Hello World!" };
unsigned char key[] = {
0x00, 0x01, 0x02, 0x03,
0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0A, 0x0B,
0x0C, 0x0D, 0x0E, 0x0F
};
char encode[64] = { 0 };
char decode[64] = { 0 };
unsigned char iv[8];
int enclen, declen, i;
xtea_t xtea;
xtea_setkey(&xtea, key);
enclen = xtea_enclen((int)strlen(text));
printf("Encode evaluate size: %d\n", enclen);
memset(iv, 0, sizeof(iv));
enclen = xtea_encode(&xtea, encode, text, (int)strlen(text), iv);
printf("Encode real size: %d\n", enclen);
declen = xtea_declen(enclen);
printf("Decode evaluate size: %d\n", declen);
memset(iv, 0, sizeof(iv));
declen = xtea_decode(&xtea, decode, encode, enclen, iv);
printf("Decode real size: %d\n", declen);
printf("Encode: ");
for (i = 0; i < enclen; ++i) {
printf("%02x ", (unsigned char)encode[i]);
}
printf("\n");
printf("Decode: %s\n", decode);
return 0;
}