-
Notifications
You must be signed in to change notification settings - Fork 26
/
tea.c
150 lines (104 loc) · 2.36 KB
/
tea.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "tea.h"
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
static void EncryptBlock(
uint32_t *v,
uint32_t *k
);
static uint32_t LoadUint32(
unsigned char b[4]
);
static void StoreUint32(
unsigned char dst[4],
uint32_t n
);
static void EncryptBlock(
uint32_t *v,
uint32_t *k
) {
/* item 22 */
uint32_t delta = 0x9e3779b9, sum = 0, i;
/* item 180001 */
i = 0;
while (i < 32) {
/* item 19 */
sum += delta;
/* item 21 */
v[0] += ((v[1]<<3) ^ k[0]) ^ (v[1] + sum) ^ ((v[1]>>5) + k[1]);
/* item 34 */
v[1] += ((v[0]<<3) ^ k[2]) ^ (v[0] + sum) ^ ((v[0]>>5) + k[3]);
/* item 180003 */
i++;
}
return;
}
static uint32_t LoadUint32(
unsigned char b[4]
) {
/* item 45 */
return (uint32_t)b[0] | (uint32_t)b[1]<<8 | (uint32_t)b[2]<<16 | (uint32_t)b[3]<<24;
}
static void StoreUint32(
unsigned char dst[4],
uint32_t n
) {
/* item 51 */
dst[0] = n;
dst[1] = n >> 8;
dst[2] = n >> 16;
dst[3] = n >> 24;
return;
}
void EncryptCBC(
unsigned char *dst,
unsigned char *src,
int len,
unsigned char key[16]
) {
/* item 109 */
unsigned char padded[8];
uint32_t v[2], k[4];
int i;
/* item 65 */
k[0] = LoadUint32(&key[0]);
k[1] = LoadUint32(&key[4]);
k[2] = LoadUint32(&key[8]);
k[3] = LoadUint32(&key[12]);
while (len >= 8) {
/* item 63 */
v[0] = LoadUint32(&src[0]);
v[1] = LoadUint32(&src[4]);
EncryptBlock(v, k);
StoreUint32(&dst[0], v[0]);
StoreUint32(&dst[4], v[1]);
src += 8;
dst += 8;
len -= 8;
}
}
int check(char *m) {
/* item 117 */
if(strlen(m)!=24){
return 0;}
unsigned char key[16] = "webasmintersting";
unsigned char c[24];
int i;
/* item 197 */
EncryptCBC(c, m, sizeof(m), key);
/* item 210 */
/* item 1980001 */
i = 0;
int s[]={153, 119, 2, 189, 47, 108, 135, 53, 85, 34, 121, 29, 246, 72, 44, 140, 185, 214, 19, 147, 203, 216, 49, 227};
i=0;
int j;
for(;i<3;i++){
for(j=0;j<8;j++){
if(c[i*8+j]!=s[i*8+7-j]){
return 0;
}
}
}
return 1;
}