forked from st1x51/DQuakePlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
crypter.c
63 lines (48 loc) · 799 Bytes
/
crypter.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
/*
DATA Decrypt
*/
char rotate(char c, int key)
{
int l = 'Z' - 'A';
c += key % l;
if(c < 'A')
c += l;
if(c > 'Z')
c -= l;
return c;
}
char encrypt(char c, int key)
{
if(c >= 'a' && c <= 'z')
c = toupper(c);
if(c >= 'A' && c <= 'Z')
c = rotate(c, key);
return c;
}
char decrypt(char c, int key)
{
if(c < 'A' || c > 'Z')
return c;
else
return rotate(c, key);
}
char *strencrypt(char *s, int key, int len)
{
int i;
char *result = malloc(len);
for(i = 0; i < len; i++)
{
result[i] = encrypt(s[i], key);
}
return result;
}
char *strdecrypt(char *s, int key, int len)
{
int i;
char *result = malloc(len);
for(i = 0; i < len; i++)
{
result[i] = decrypt(s[i], -key);
}
return result;
}