-
Notifications
You must be signed in to change notification settings - Fork 9
/
secret.c
55 lines (45 loc) · 886 Bytes
/
secret.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
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
int debug = 0;
long compare1(const char * s)
{
static const char secret[] = "tfufdbtuspopnz";
for (size_t i = 0 ; i < sizeof(secret)-1 ; i++)
{
char c1 = *s++;
char c2 = secret[i] - 1;
if (debug)
printf("%zu: '%c' '%c'\n", i, c1, c2);
if (c1 != c2)
return -0xF00D;
}
return 0;
}
char * get_secret(void)
{
static const uint8_t secret[] = {
0xd1, 0xca, 0xca, 0x85, 0xc8, 0xc4, 0xcb, 0xdc, 0x85, 0xd6, 0xc0, 0xc6,
0xd7, 0xc0, 0xd1, 0xd6
};
char * s = malloc(sizeof(secret));
for (size_t i = 0 ; i < sizeof(secret) ; i++)
{
s[i] = secret[i] ^ 0xA5;
}
return s;
}
int main(int argc, char ** argv)
{
if (argc != 2)
goto failure;
int rc;
rc = compare1(argv[1]);
if (rc < 0)
goto failure;
printf("magic words: %s\n", get_secret());
return 0;
failure:
printf("sorry!\n");
return -1;
}