forked from NoraCodes/crackmes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrackme04.c
38 lines (30 loc) · 862 Bytes
/
crackme04.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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// Never stores the correct password; instead, accepts any password
// whose length is 16 and whose characters, in ASCII, sum to 1652.
// This is 16 * 110 + 2, so the characters average on 'n', but two must be higher.
#define CORRECT_LEN 16
#define CORRECT_SUM 1762
int main(int argc, char** argv) {
char correct = 0;
if (argc != 2) {
printf("Need exactly one argument.\n");
return -1;
}
// Loop over the whole string
int i = 0;
int sum = 0;
while (argv[1][i] != 0) {
sum += argv[1][i];
i++;
}
correct = (i == CORRECT_LEN) && (sum == CORRECT_SUM);
if (correct) {
printf("Yes, %s is correct!\n", argv[1]);
return 0;
} else {
printf("No, %s is not correct.\n", argv[1]);
return 1;
}
}