aboutsummaryrefslogtreecommitdiff
path: root/2015
diff options
context:
space:
mode:
Diffstat (limited to '2015')
-rw-r--r--2015/src/day04.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/2015/src/day04.cpp b/2015/src/day04.cpp
new file mode 100644
index 0000000..bc24177
--- /dev/null
+++ b/2015/src/day04.cpp
@@ -0,0 +1,52 @@
1// Standard C++
2#include <array>
3#include <fstream>
4#include <iostream>
5#include <string>
6
7// Standard C
8#include <cstring>
9
10// System
11#include <md5.h>
12
13using namespace std;
14
15void
16brute_force(string_view puzzle, size_t length)
17{
18 array<char, MD5_DIGEST_STRING_LENGTH> digest{};
19
20 string input;
21 for ( unsigned long counter = 0;; ++counter ) {
22 input = puzzle;
23 input += to_string(counter);
24 MD5Data(input.data(), input.size(), digest.data());
25
26 if ( memcmp(digest.data(), "00000000000", length) == 0 ) {
27 cout << digest.data() << ": " << counter << endl;
28 return;
29 }
30 }
31}
32
33void
34part1(string_view puzzle)
35{
36 brute_force(puzzle, 5);
37}
38
39void
40part2(string_view puzzle)
41{
42 brute_force(puzzle, 6);
43}
44
45int
46main()
47{
48 string puzzle = "yzbqklnj";
49
50 part1(puzzle);
51 part2(puzzle);
52}