forked from JonathanSalwan/Tigress_protection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample4.c
39 lines (30 loc) · 750 Bytes
/
sample4.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
/*
** adler32
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
const uint32_t MOD_ADLER = 65521;
uint32_t SECRET(unsigned long input) {
unsigned char *data = (unsigned char*)&input;
size_t len = sizeof(input);
uint32_t a = 1, b = 0;
size_t index;
/* Process each byte of the data in order */
for (index = 0; index < len; ++index) {
a = (a + data[index]) % MOD_ADLER;
b = (b + a) % MOD_ADLER;
}
return (b << 16) | a;
}
int main(int argc, char **argv) {
if (argc < 2) {
printf("Call this program with 1 arguments\n");
return 1;
}
unsigned long input = strtoul(argv[1], 0, 10);
uint32_t output = SECRET(input);
printf("%u\n", output);
return 0;
}