blob: e1414072debf2a28fa271b8c30e26046fc9471e4 (
plain)
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
|
#include "aoc.h"
#include "md5.h"
#include <string.h>
namespace aoc2016 {
void day5(const char* secret, int len, char pass1[], char pass2[]) {
char buf[128] = {0};
int l = strlen(secret);
memcpy(buf, secret, len);
int i = 0;
int x1 = len;
int x2 = 0;
while (i < INT32_MAX && x2 < 8) {
sprintf(buf + l, "%d", i);
char* hash = md5sum(buf);
if (lead_zeros(hash) >= 5) {
printf("%d %s\n", i, hash);
if (x1 > 0) {
pass1[len - x1] = hash[5];
x1--;
}
if (hash[5] >= '0' && hash[5] <= '7' && pass2[hash[5] - '0'] == '\0') {
pass2[hash[5] - '0'] = hash[6];
x2 += 1;
}
}
i++;
}
}
} // namespace aoc2016
|