-
Notifications
You must be signed in to change notification settings - Fork 2
/
encryption.c
59 lines (58 loc) · 1.85 KB
/
encryption.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
#include "encryption.h"
void encryption_gen_md5(const void *data, unsigned long size_input, unsigned char *result)
{
MD5(data, size_input, result);
}
void encryption_gen_xor(unsigned char *data_a, unsigned char *data_b, unsigned long size_input, unsigned char *result, unsigned long size_output)
{
unsigned long size = size_input > size_output ? size_output : size_input;
for (unsigned long i = 0; i < size; ++i)
{
result[i] = data_a[i] ^ data_b[i];
}
}
void encryption_gen_ror(unsigned char *data, unsigned long size, unsigned char *result)
{
for (unsigned long i = 0; i < size; ++i)
{
result[i] = (unsigned char)((data[i] << 3 ) + (data[i] >> 5));
}
}
void encryption_gen_checksum(unsigned char *data, unsigned long size_input, unsigned char *result, unsigned long size_output)
{
unsigned long sum_checksum = 1234;
for (unsigned long i = 0; i < size_input; i += 4)
{
unsigned long tmp = 0;
for (int j = 4; j > 0; --j)
{
tmp *= 256;
tmp += (unsigned long)data[i + j - 1];
}
sum_checksum ^= tmp;
}
sum_checksum = (1968 * sum_checksum) & 0xffffffff;
for (unsigned long i = 0; i < size_output; ++i)
{
result[i] = (unsigned char)(sum_checksum >> (i * 8) & 0xff);
}
}
void encryption_gen_crc(unsigned char *data, unsigned long size_input, unsigned char *result, unsigned long size_output)
{
unsigned long sum_crc = 0;
for (unsigned long i = 0; i < size_input; i += 2)
{
unsigned long tmp = 0;
for (unsigned long j = 2; j > 0; --j)
{
tmp *= 2 << 7;
tmp += (unsigned long)data[i + j - 1];
}
sum_crc ^= tmp;
}
sum_crc = (711 * sum_crc);
for (unsigned long i = 0; i < size_output; ++i)
{
result[i] = (unsigned char)(sum_crc >> (i * 8) & 0xff);
}
}