Commit da67630c authored by Canvas123's avatar Canvas123

Initial commit

parents
# Prerequisites
*.d
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Precompiled Headers
*.gch
*.pch
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Fortran module files
*.mod
*.smod
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
# Executables
*.exe
*.out
*.app
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#ifdef WIN32
#define DLL_EXPORT extern "C" __declspec(dllexport)
#else
#define DLL_EXPORT __attribute__((visibility("default")))
#endif
uint32_t table[256] = {
0, 175, 350, 497, 700, 531, 994, 845,
1400, 1495, 1062, 1161, 1988, 1899, 1690, 1589,
2800, 2655, 2990, 2817, 2124, 2275, 2322, 2493,
3976, 3879, 3798, 3705, 3380, 3483, 3178, 3269,
5600, 5455, 5310, 5137, 5980, 6131, 5634, 5805,
4248, 4151, 4550, 4457, 4644, 4747, 4986, 5077,
7952, 8127, 7758, 7905, 7596, 7427, 7410, 7261,
6760, 6855, 6966, 7065, 6356, 6267, 6538, 6437,
11200, 11119, 10910, 10801, 10620, 10707, 10274, 10381,
11960, 11799, 12262, 12105, 11268, 11435, 11610, 11765,
8496, 8607, 8302, 8385, 9100, 8995, 8914, 8829,
9288, 9447, 9494, 9657, 9972, 9819, 10154, 9989,
15904, 16015, 16254, 16337, 15516, 15411, 15810, 15725,
15192, 15351, 14854, 15017, 14820, 14667, 14522, 14357,
13520, 13439, 13710, 13601, 13932, 14019, 14130, 14237,
12712, 12551, 12534, 12377, 13076, 13243, 12874, 13029,
22400, 22319, 22238, 22129, 21820, 21907, 21602, 21709,
21240, 21079, 21414, 21257, 20548, 20715, 20762, 20917,
23920, 24031, 23598, 23681, 24524, 24419, 24210, 24125,
22536, 22695, 22870, 23033, 23220, 23067, 23530, 23365,
16992, 17103, 17214, 17297, 16604, 16499, 16770, 16685,
18200, 18359, 17990, 18153, 17828, 17675, 17658, 17493,
18576, 18495, 18894, 18785, 18988, 19075, 19314, 19421,
19944, 19783, 19638, 19481, 20308, 20475, 19978, 20133,
31808, 31983, 32030, 32177, 32508, 32339, 32674, 32525,
31032, 31127, 30822, 30921, 31620, 31531, 31450, 31349,
30384, 30239, 30702, 30529, 29708, 29859, 30034, 30205,
29640, 29543, 29334, 29241, 29044, 29147, 28714, 28805,
27040, 26895, 26878, 26705, 27420, 27571, 27202, 27373,
27864, 27767, 28038, 27945, 28260, 28363, 28474, 28565,
25424, 25599, 25102, 25249, 25068, 24899, 24754, 24605,
26152, 26247, 26486, 26585, 25748, 25659, 26058, 25957
};
extern "C" DLL_EXPORT uint32_t checksum(char* bytes, size_t size) {
uint32_t s = 0xFFFFFFFF;
for(size_t i=0; i < size; i++) {
s = table[(bytes[i] & 0xFF) ^ (s >> 24)] ^ (s << 8);
}
return s;
}
extern "C" DLL_EXPORT uint32_t get_next_key(uint32_t current_key, uint8_t current_byte) {
uint32_t a = current_byte + current_key;
a = ((a << 12) + a + 0x7ED55D16);
a = ((a >> 19) ^ a ^ 0xC761C23C);
a = ((a << 5) + a + 0x165667B1);
a = ((a << 9) ^ (a - 0x2C5D9B94));
a = ((a << 3) + a - 0x28FB93B);
a = ((a >> 16) ^ a ^ 0xB55A4F09);
return a;
}
extern "C" DLL_EXPORT char* encrypt(char* bytes, uint32_t key, size_t size) {
for (size_t i=0; i < size; i++){
bytes[i] ^= key & 0xFF;
key = get_next_key(key, bytes[i]);
}
return bytes;
}
extern "C" DLL_EXPORT char* decrypt(char* bytes, uint32_t key, size_t size) {
char old_byte;
for (size_t i=0; i < size; i++){
old_byte = bytes[i];
bytes[i] ^= key & 0xFF;
key = get_next_key(key, old_byte);
}
return bytes;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment