-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathmystery.c
68 lines (59 loc) · 1.42 KB
/
mystery.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
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* Binary challenge used for the Radare 2 Primer.
* By superkojiman - http://blog.techorganic.com
*
*/
#include <stdio.h>
#include <string.h>
int check_password(char *pass) {
int stage2 = 0;
/* stage 1, check the first 5 letters */
if (pass[0] == 'h') {
if (pass[1] == 'e') {
if (pass[2] == 'l') {
if (pass[3] == 'l') {
if (pass[4] == 'o') {
stage2 = 1;
}
}
}
}
}
/* stage 2, check the next 5 letters */
if (stage2) {
if (pass[5] == 'w') {
if (pass[6] == 'o') {
if (pass[7] == 'r') {
if (pass[8] == 'l') {
if (pass[9] == 'd') {
return 0;
}
}
}
}
}
} else {
return -1;
}
}
int check_pass_len(char *pass) {
int i = 0;
while(pass[i] != '\0') {
i++;
}
return i;
}
int main(int argc, char *argv[]) {
char pass[10];
int stage2 = 0;
printf("Enter password: ");
scanf("%s", pass);
printf("Got [%s]\n", pass);
if ((check_pass_len(pass) == 10) &&
(check_password(pass) == 0)) {
printf("Win!\n");
} else {
printf("Fail!\n");
}
return 0;
}