#include "aoc.h" #include "md5.h" #include 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