2022-02-08 21:49:56 +00:00
|
|
|
/*
|
|
|
|
DATA Decrypt
|
|
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-06-17 23:48:48 +00:00
|
|
|
void* Q_malloc(size_t);
|
|
|
|
|
2022-02-08 21:49:56 +00:00
|
|
|
char *strencrypt(char *s, int key, int len)
|
|
|
|
{
|
2024-06-17 23:48:48 +00:00
|
|
|
int i;
|
2023-02-02 17:44:45 +00:00
|
|
|
char *result = Q_malloc(len);
|
2022-02-08 21:49:56 +00:00
|
|
|
for(i = 0; i < len; i++)
|
2024-06-17 23:48:48 +00:00
|
|
|
result[i] = encrypt(s[i], key);
|
|
|
|
return result;
|
2022-02-08 21:49:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *strdecrypt(char *s, int key, int len)
|
|
|
|
{
|
2024-06-17 23:48:48 +00:00
|
|
|
int i;
|
2023-02-02 17:44:45 +00:00
|
|
|
char *result = Q_malloc(len);
|
2022-02-08 21:49:56 +00:00
|
|
|
for(i = 0; i < len; i++)
|
2024-06-17 23:48:48 +00:00
|
|
|
result[i] = decrypt(s[i], -key);
|
2022-02-08 21:49:56 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|