forked from NoraCodes/crackmes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrackme05e.c
64 lines (50 loc) · 1.12 KB
/
crackme05e.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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void succeed(char* string) {
printf("Yes, %s is correct!\n", string);
exit(0);
}
void fail(char* string) {
printf("No, %s is not correct.\n", string);
exit(1);
}
int check_with_mod(char* substring, int n, int mod) {
int sum = 0;
for (int i = 0; i < n; i++) {
sum = sum + substring[i];
}
return (sum % mod) == 0;
}
int main(int argc, char** argv) {
if (argc != 2) {
printf("Need exactly one argument.\n");
return -1;
}
char* input = argv[1];
int len = strnlen(input, 1000);
if (len != 16) {
fail(input);
}
// Add some fixed characters
if (input[2] != 'm') {
fail(input);
}
if (input[10] != '\'') {
fail(input);
}
// Make the actual modulo checks
if (!check_with_mod(input, 4, 2)) {
fail(input);
}
if (!check_with_mod(input + 4, 4, 3)) {
fail(input);
}
if (!check_with_mod(input + 8, 4, 5)) {
fail(input);
}
if (!check_with_mod(input + 12, 4, 2)) {
fail(input);
}
succeed(input);
}