aoc-2015/day4/so1.cpp
2020-11-30 20:24:22 +01:00

39 lines
750 B
C++

#include <iterator>
#include <string>
#include <iostream>
#include <nettle/md5.h>
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] & 0xf0)) {
has_non_zero = true;
}
if(!has_non_zero) {
found = true;
cout << "Result: " << n << endl;
}
n++;
}
}