-
Notifications
You must be signed in to change notification settings - Fork 10
/
test1.c
50 lines (45 loc) · 909 Bytes
/
test1.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
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <stdlib.h>
#include <fcntl.h>
int strcmp2(char* a, char* b) {
while((*a == *b) && (*a != '\0')) {
a++;
b++;
}
return *a - *b;
}
int strcmp3(const char* s1, const char* s2)
{
while(*s1 && (*s1==*s2))
s1++,s2++;
return *(const unsigned char*)s1-*(const unsigned char*)s2;
}
int main(void)
{
char key[] = "magic";
char key2[] = "cigam";
int fd = 0;
char buf[16] = {0};
char *r = buf;
fd = open("key.txt", O_RDONLY);
read(fd, r, 16);
close(fd);
if(strcmp(key, r) == 0) {
printf("Success!\n");
return 0;
//printf("Correct!\n");
} else {
if(strcmp2(key2, r) == 0) {
char ptr[1] = {0};
strcpy(ptr, "cigamcigamcigam");
if(strcmp2(ptr, r) == 0) {
return 2;
}
}
//printf("Wrong %d. %s\n", strcmp3(key, r), ptr);
return 1;
}
return 0;
}