aoc-2015/day4/so2.cpp

40 lines
742 B
C++
Raw Permalink Normal View History

2020-11-30 19:24:22 +00:00
#include <iostream>
#include <iterator>
#include <nettle/md5.h>
#include <string>
using namespace std;
int main() {
string input;
cout << "Initializing" << endl << "Input: ";
cin >> input;
md5_ctx ctx;
md5_init(&ctx);
bool found = false;
unsigned long long n = 1;
while (!found) {
string data = input + to_string(n);
size_t len_total = data.length();
md5_update(&ctx, len_total, (uint8_t *)data.c_str());
uint8_t result[MD5_DIGEST_SIZE];
md5_digest(&ctx, MD5_DIGEST_SIZE, result);
bool has_non_zero = false;
if (result[0] || result[1] || result[2]) {
has_non_zero = true;
}
if (!has_non_zero) {
found = true;
cout << "Result: " << n << endl;
}
n++;
}
}