2015 / Day 04
The Ideal Stocking Stuffer
Read the original puzzle on adventofcode.com ↗
The solution
solution.c
1#include "aoc.h"
2
3#include <string.h>
4
5/* 2015 day 4. MD5 AdventCoins.
6 *
7 * Brute force has to survive the wasm execution budget, so this MD5 is
8 * hand-unrolled: the message schedule and all 64 steps are straight-line
9 * arithmetic, which the coverage hook sees as a handful of basic blocks
10 * instead of hundreds of loop iterations. The decimal suffix is kept in
11 * the message buffer and bumped in place; the padding is rebuilt only
12 * when the digit count grows. About 25 budget checks per candidate.
13 */
14
15enum { KEYMAX = 64 };
16
17enum { CAP = 2000000 };
18
19enum { PAD55 = 55 }; /* payload beyond 55 bytes needs a second block */
20
21#define MD5ROL(x, s) (((x) << (s)) | ((x) >> (32 - (s))))
22#define MD5F(x, y, z) (((x) & (y)) | (~(x) & (z)))
23#define MD5G(x, y, z) (((x) & (z)) | ((y) & ~(z)))
24#define MD5H(x, y, z) ((x) ^ (y) ^ (z))
25#define MD5I(x, y, z) ((y) ^ ((x) | ~(z)))
26#define MD5STEP(fn, a, b, c, d, x, s, k) \
27 a = b + MD5ROL(a + fn(b, c, d) + (x) + (uint32_t)(k), (s))
28
29static void md5_block(uint32_t st[4], const uint8_t *blk) {
30 uint32_t w[16];
31 uint32_t A = st[0], B = st[1], C = st[2], D = st[3];
32
33 w[0] = (uint32_t)blk[0] | ((uint32_t)blk[1] << 8) |
34 ((uint32_t)blk[2] << 16) | ((uint32_t)blk[3] << 24);
35 w[1] = (uint32_t)blk[4] | ((uint32_t)blk[5] << 8) |
36 ((uint32_t)blk[6] << 16) | ((uint32_t)blk[7] << 24);
37 w[2] = (uint32_t)blk[8] | ((uint32_t)blk[9] << 8) |
38 ((uint32_t)blk[10] << 16) | ((uint32_t)blk[11] << 24);
39 w[3] = (uint32_t)blk[12] | ((uint32_t)blk[13] << 8) |
40 ((uint32_t)blk[14] << 16) | ((uint32_t)blk[15] << 24);
41 w[4] = (uint32_t)blk[16] | ((uint32_t)blk[17] << 8) |
42 ((uint32_t)blk[18] << 16) | ((uint32_t)blk[19] << 24);
43 w[5] = (uint32_t)blk[20] | ((uint32_t)blk[21] << 8) |
44 ((uint32_t)blk[22] << 16) | ((uint32_t)blk[23] << 24);
45 w[6] = (uint32_t)blk[24] | ((uint32_t)blk[25] << 8) |
46 ((uint32_t)blk[26] << 16) | ((uint32_t)blk[27] << 24);
47 w[7] = (uint32_t)blk[28] | ((uint32_t)blk[29] << 8) |
48 ((uint32_t)blk[30] << 16) | ((uint32_t)blk[31] << 24);
49 w[8] = (uint32_t)blk[32] | ((uint32_t)blk[33] << 8) |
50 ((uint32_t)blk[34] << 16) | ((uint32_t)blk[35] << 24);
51 w[9] = (uint32_t)blk[36] | ((uint32_t)blk[37] << 8) |
52 ((uint32_t)blk[38] << 16) | ((uint32_t)blk[39] << 24);
53 w[10] = (uint32_t)blk[40] | ((uint32_t)blk[41] << 8) |
54 ((uint32_t)blk[42] << 16) | ((uint32_t)blk[43] << 24);
55 w[11] = (uint32_t)blk[44] | ((uint32_t)blk[45] << 8) |
56 ((uint32_t)blk[46] << 16) | ((uint32_t)blk[47] << 24);
57 w[12] = (uint32_t)blk[48] | ((uint32_t)blk[49] << 8) |
58 ((uint32_t)blk[50] << 16) | ((uint32_t)blk[51] << 24);
59 w[13] = (uint32_t)blk[52] | ((uint32_t)blk[53] << 8) |
60 ((uint32_t)blk[54] << 16) | ((uint32_t)blk[55] << 24);
61 w[14] = (uint32_t)blk[56] | ((uint32_t)blk[57] << 8) |
62 ((uint32_t)blk[58] << 16) | ((uint32_t)blk[59] << 24);
63 w[15] = (uint32_t)blk[60] | ((uint32_t)blk[61] << 8) |
64 ((uint32_t)blk[62] << 16) | ((uint32_t)blk[63] << 24);
65 MD5STEP(MD5F, A, B, C, D, w[0], 7, 0xd76aa478u);
66 MD5STEP(MD5F, D, A, B, C, w[1], 12, 0xe8c7b756u);
67 MD5STEP(MD5F, C, D, A, B, w[2], 17, 0x242070dbu);
68 MD5STEP(MD5F, B, C, D, A, w[3], 22, 0xc1bdceeeu);
69 MD5STEP(MD5F, A, B, C, D, w[4], 7, 0xf57c0fafu);
70 MD5STEP(MD5F, D, A, B, C, w[5], 12, 0x4787c62au);
71 MD5STEP(MD5F, C, D, A, B, w[6], 17, 0xa8304613u);
72 MD5STEP(MD5F, B, C, D, A, w[7], 22, 0xfd469501u);
73 MD5STEP(MD5F, A, B, C, D, w[8], 7, 0x698098d8u);
74 MD5STEP(MD5F, D, A, B, C, w[9], 12, 0x8b44f7afu);
75 MD5STEP(MD5F, C, D, A, B, w[10], 17, 0xffff5bb1u);
76 MD5STEP(MD5F, B, C, D, A, w[11], 22, 0x895cd7beu);
77 MD5STEP(MD5F, A, B, C, D, w[12], 7, 0x6b901122u);
78 MD5STEP(MD5F, D, A, B, C, w[13], 12, 0xfd987193u);
79 MD5STEP(MD5F, C, D, A, B, w[14], 17, 0xa679438eu);
80 MD5STEP(MD5F, B, C, D, A, w[15], 22, 0x49b40821u);
81 MD5STEP(MD5G, A, B, C, D, w[1], 5, 0xf61e2562u);
82 MD5STEP(MD5G, D, A, B, C, w[6], 9, 0xc040b340u);
83 MD5STEP(MD5G, C, D, A, B, w[11], 14, 0x265e5a51u);
84 MD5STEP(MD5G, B, C, D, A, w[0], 20, 0xe9b6c7aau);
85 MD5STEP(MD5G, A, B, C, D, w[5], 5, 0xd62f105du);
86 MD5STEP(MD5G, D, A, B, C, w[10], 9, 0x02441453u);
87 MD5STEP(MD5G, C, D, A, B, w[15], 14, 0xd8a1e681u);
88 MD5STEP(MD5G, B, C, D, A, w[4], 20, 0xe7d3fbc8u);
89 MD5STEP(MD5G, A, B, C, D, w[9], 5, 0x21e1cde6u);
90 MD5STEP(MD5G, D, A, B, C, w[14], 9, 0xc33707d6u);
91 MD5STEP(MD5G, C, D, A, B, w[3], 14, 0xf4d50d87u);
92 MD5STEP(MD5G, B, C, D, A, w[8], 20, 0x455a14edu);
93 MD5STEP(MD5G, A, B, C, D, w[13], 5, 0xa9e3e905u);
94 MD5STEP(MD5G, D, A, B, C, w[2], 9, 0xfcefa3f8u);
95 MD5STEP(MD5G, C, D, A, B, w[7], 14, 0x676f02d9u);
96 MD5STEP(MD5G, B, C, D, A, w[12], 20, 0x8d2a4c8au);
97 MD5STEP(MD5H, A, B, C, D, w[5], 4, 0xfffa3942u);
98 MD5STEP(MD5H, D, A, B, C, w[8], 11, 0x8771f681u);
99 MD5STEP(MD5H, C, D, A, B, w[11], 16, 0x6d9d6122u);
100 MD5STEP(MD5H, B, C, D, A, w[14], 23, 0xfde5380cu);
101 MD5STEP(MD5H, A, B, C, D, w[1], 4, 0xa4beea44u);
102 MD5STEP(MD5H, D, A, B, C, w[4], 11, 0x4bdecfa9u);
103 MD5STEP(MD5H, C, D, A, B, w[7], 16, 0xf6bb4b60u);
104 MD5STEP(MD5H, B, C, D, A, w[10], 23, 0xbebfbc70u);
105 MD5STEP(MD5H, A, B, C, D, w[13], 4, 0x289b7ec6u);
106 MD5STEP(MD5H, D, A, B, C, w[0], 11, 0xeaa127fau);
107 MD5STEP(MD5H, C, D, A, B, w[3], 16, 0xd4ef3085u);
108 MD5STEP(MD5H, B, C, D, A, w[6], 23, 0x04881d05u);
109 MD5STEP(MD5H, A, B, C, D, w[9], 4, 0xd9d4d039u);
110 MD5STEP(MD5H, D, A, B, C, w[12], 11, 0xe6db99e5u);
111 MD5STEP(MD5H, C, D, A, B, w[15], 16, 0x1fa27cf8u);
112 MD5STEP(MD5H, B, C, D, A, w[2], 23, 0xc4ac5665u);
113 MD5STEP(MD5I, A, B, C, D, w[0], 6, 0xf4292244u);
114 MD5STEP(MD5I, D, A, B, C, w[7], 10, 0x432aff97u);
115 MD5STEP(MD5I, C, D, A, B, w[14], 15, 0xab9423a7u);
116 MD5STEP(MD5I, B, C, D, A, w[5], 21, 0xfc93a039u);
117 MD5STEP(MD5I, A, B, C, D, w[12], 6, 0x655b59c3u);
118 MD5STEP(MD5I, D, A, B, C, w[3], 10, 0x8f0ccc92u);
119 MD5STEP(MD5I, C, D, A, B, w[10], 15, 0xffeff47du);
120 MD5STEP(MD5I, B, C, D, A, w[1], 21, 0x85845dd1u);
121 MD5STEP(MD5I, A, B, C, D, w[8], 6, 0x6fa87e4fu);
122 MD5STEP(MD5I, D, A, B, C, w[15], 10, 0xfe2ce6e0u);
123 MD5STEP(MD5I, C, D, A, B, w[6], 15, 0xa3014314u);
124 MD5STEP(MD5I, B, C, D, A, w[13], 21, 0x4e0811a1u);
125 MD5STEP(MD5I, A, B, C, D, w[4], 6, 0xf7537e82u);
126 MD5STEP(MD5I, D, A, B, C, w[11], 10, 0xbd3af235u);
127 MD5STEP(MD5I, C, D, A, B, w[2], 15, 0x2ad7d2bbu);
128 MD5STEP(MD5I, B, C, D, A, w[9], 21, 0xeb86d391u);
129
130 st[0] += A;
131 st[1] += B;
132 st[2] += C;
133 st[3] += D;
134}
135
136static size_t key_from_input(slice in, char *key) {
137 size_t len = in.l;
138 size_t i;
139 if (len > 0 && in.p[len - 1] == '\n') {
140 len--;
141 if (len > 0 && in.p[len - 1] == '\r') {
142 len--;
143 }
144 }
145 aoc_assert(len > 0, "empty key");
146 aoc_assert(len <= KEYMAX, "key too long");
147 for (i = 0; i < len; i++) {
148 uint8_t c = in.p[i];
149 aoc_assert(c >= 32 && c < 127 && c != '\n' && c != '\r', "bad key");
150 }
151 aoc_assert(len == in.l || in.p[len] == '\n' || in.p[len] == '\r',
152 "bad key");
153 memcpy(key, in.p, len);
154 key[len] = 0;
155 return len;
156}
157
158struct hunt {
159 const char *key;
160 size_t base; /* digits live at msg[base .. base+ndig) */
161 int ndig;
162 int two; /* payload needs a second MD5 block */
163 uint8_t msg[128];
164};
165
166/* Full reset: used at the start and whenever the digit count grows, so
167 * the padding bytes (0x80 and the length) are always rebuilt from a
168 * clean buffer. Rare on purpose; the hot path never touches this.
169 */
170static void rebuild(struct hunt *h) {
171 size_t total;
172 uint64_t bits;
173 int i;
174 memset(h->msg, 0, sizeof(h->msg));
175 memcpy(h->msg, h->key, h->base);
176 h->msg[h->base] = '1';
177 for (i = 1; i < h->ndig; i++) {
178 h->msg[h->base + i] = '0';
179 }
180 total = h->base + (size_t)h->ndig;
181 h->two = total > (size_t)PAD55;
182 h->msg[total] = 0x80;
183 bits = (uint64_t)total * 8u;
184 if (!h->two) {
185 for (i = 0; i < 8; i++) {
186 h->msg[56 + i] = (uint8_t)((bits >> (8 * i)) & 0xffu);
187 }
188 } else {
189 for (i = 0; i < 8; i++) {
190 h->msg[112 + i] = (uint8_t)((bits >> (8 * i)) & 0xffu);
191 }
192 }
193}
194
195/* n += 1, in place. When the digits wrap the count grows and the whole
196 * tail is rebuilt.
197 */
198static void bump(struct hunt *h) {
199 int i = h->ndig - 1;
200 for (;;) {
201 if (h->msg[h->base + i] < '9') {
202 h->msg[h->base + i]++;
203 return;
204 }
205 h->msg[h->base + i] = '0';
206 if (i == 0) {
207 h->ndig++;
208 rebuild(h);
209 return;
210 }
211 i--;
212 }
213}
214
215static int coin_hits(struct hunt *h, int six) {
216 uint32_t st[4];
217 st[0] = 0x67452301u;
218 st[1] = 0xefcdab89u;
219 st[2] = 0x98badcfeu;
220 st[3] = 0x10325476u;
221 md5_block(st, h->msg);
222 if (h->two) {
223 md5_block(st, h->msg + 64);
224 }
225 /* Digest bytes 0..2 are the low 24 bits of A. Six leading zeroes
226 * means bytes 0..2 are all zero; five means byte 2 has a zero high
227 * nibble only, so that mask skips bits 16..19.
228 */
229 if (six) {
230 return (st[0] & 0x00ffffffu) == 0;
231 }
232 return (st[0] & 0x00f0ffffu) == 0;
233}
234
235static int64_t hunt(slice input, int six) {
236 char key[KEYMAX + 1];
237 struct hunt h;
238 size_t keylen = key_from_input(input, key);
239 uint32_t n;
240
241 h.key = key;
242 h.base = keylen;
243 h.ndig = 1;
244 rebuild(&h);
245
246 for (n = 1; n <= (uint32_t)CAP; n++) {
247 if (coin_hits(&h, six)) {
248 return (int64_t)n;
249 }
250 bump(&h);
251 }
252 aoc_assert(0, "no adventcoin");
253 return 0;
254}
255
256slice part1(slice input) {
257 return slice_from_i64(hunt(input, 0));
258}
259
260slice part2(slice input) {
261 return slice_from_i64(hunt(input, 1));
262}
263
264const struct aoc_method aoc_methods[] = {
265 {0, 0},
266};aoc.h
1#ifndef AOC_H
2#define AOC_H
3
4#include <stdarg.h>
5#include <stddef.h>
6#include <stdint.h>
7#include <stdlib.h>
8#include <string.h>
9
10/* The only required boundary between infra and a solution.
11 * `input` is read-only and is not owned by the solution.
12 * The returned slice is allocated with malloc. It is the only
13 * block still live when the function returns. Infra copies it
14 * and then frees it.
15 */
16typedef struct {
17 uint8_t *p;
18 size_t l;
19} slice;
20
21/* p is null and l is 0. Infra uses this when a run has no output. */
22static const slice empty_slice = {0};
23
24typedef slice (*aoc_fn)(slice);
25
26/* One named method. The name is a C identifier, at most 31
27 * characters, and it is the URL suffix: /YYYY/D/P/<name>.
28 * estimate and span are examples, not a fixed list. A day
29 * exports as many as it wants. The array ends with {0, 0}.
30 * part1 and part2 are not entries in this list.
31 */
32struct aoc_method {
33 const char *name;
34 aoc_fn fn;
35};
36
37slice part1(slice input);
38slice part2(slice input);
39
40extern const struct aoc_method aoc_methods[];
41
42/* Provided by the runtime. Records msg and returns. */
43void aoc_fail(const char *msg);
44
45/* Stops the run when cond is false and reports msg. */
46_Noreturn void aoc_assert_fail(const char *msg);
47#ifndef aoc_assert
48#define aoc_assert(cond, msg) \
49 do { \
50 if (!(cond)) { \
51 aoc_assert_fail(msg); \
52 } \
53 } while (0)
54#endif
55
56/* Decimal text of a uint64_t is at most 20 digits. A sign and a
57 * little spare fit here. Size a number buffer from this.
58 */
59enum { AOC_I64_TEXT = 32 };
60
61/* Decimal digits of v. No sign. d has room for 20 digits. */
62static inline char *aoc_u64_text(char *d, uint64_t v) {
63 char tmp[AOC_I64_TEXT];
64 char *end = tmp + AOC_I64_TEXT;
65 char *p = end;
66 size_t n;
67 do {
68 *--p = (char)('0' + (v % 10ull));
69 v /= 10ull;
70 } while (v);
71 n = (size_t)(end - p);
72 memcpy(d, p, n);
73 return d + n;
74}
75
76/* Decimal digits of v. The minimum int64_t is not negated. */
77static inline char *aoc_i64_text(char *d, int64_t v) {
78 uint64_t u;
79 if (v < 0) {
80 *d++ = '-';
81 u = (uint64_t)(-(v + 1)) + 1ull;
82 } else {
83 u = (uint64_t)v;
84 }
85 return aoc_u64_text(d, u);
86}
87
88/* n values, one space between them. The author knows the order. */
89static inline char *aoc_u64s(char *d, const uint64_t *v, size_t n) {
90 size_t i;
91 for (i = 0; i < n; i++) {
92 if (i) {
93 *d++ = ' ';
94 }
95 d = aoc_u64_text(d, v[i]);
96 }
97 return d;
98}
99
100static inline char *aoc_i64s(char *d, const int64_t *v, size_t n) {
101 size_t i;
102 for (i = 0; i < n; i++) {
103 if (i) {
104 *d++ = ' ';
105 }
106 d = aoc_i64_text(d, v[i]);
107 }
108 return d;
109}
110
111static inline char *aoc_ints(char *d, const int *v, size_t n) {
112 size_t i;
113 for (i = 0; i < n; i++) {
114 if (i) {
115 *d++ = ' ';
116 }
117 d = aoc_i64_text(d, (int64_t)v[i]);
118 }
119 return d;
120}
121
122/* Write fmt at buf. Return the cursor for the next call.
123 * %d takes int. %i takes int64_t. %u takes uint64_t.
124 * %s takes a C string. %% is a percent sign.
125 * A literal run is memcpy.
126 * %D takes (int *, size_t). %I takes (int64_t *, size_t).
127 * %U takes (uint64_t *, size_t). One space between values.
128 */
129static inline char *aoc_vprintf(const char *fmt, char *buf, va_list ap) {
130 while (*fmt) {
131 const char *lit = fmt;
132 size_t n;
133 while (*fmt && *fmt != '%') {
134 fmt++;
135 }
136 n = (size_t)(fmt - lit);
137 if (n) {
138 memcpy(buf, lit, n);
139 buf += n;
140 }
141 if (*fmt != '%') {
142 break;
143 }
144 fmt++;
145 if (*fmt == '%') {
146 *buf++ = '%';
147 fmt++;
148 continue;
149 }
150 if (*fmt == 's') {
151 const char *s = va_arg(ap, const char *);
152 n = strlen(s);
153 if (n) {
154 memcpy(buf, s, n);
155 buf += n;
156 }
157 fmt++;
158 continue;
159 }
160 if (*fmt == 'd') {
161 buf = aoc_i64_text(buf, (int64_t)va_arg(ap, int));
162 fmt++;
163 continue;
164 }
165 if (*fmt == 'i') {
166 buf = aoc_i64_text(buf, va_arg(ap, int64_t));
167 fmt++;
168 continue;
169 }
170 if (*fmt == 'u') {
171 buf = aoc_u64_text(buf, va_arg(ap, uint64_t));
172 fmt++;
173 continue;
174 }
175 if (*fmt == 'D') {
176 const int *v = va_arg(ap, int *);
177 buf = aoc_ints(buf, v, va_arg(ap, size_t));
178 fmt++;
179 continue;
180 }
181 if (*fmt == 'I') {
182 const int64_t *v = va_arg(ap, int64_t *);
183 buf = aoc_i64s(buf, v, va_arg(ap, size_t));
184 fmt++;
185 continue;
186 }
187 if (*fmt == 'U') {
188 const uint64_t *v = va_arg(ap, uint64_t *);
189 buf = aoc_u64s(buf, v, va_arg(ap, size_t));
190 fmt++;
191 continue;
192 }
193 aoc_assert(0, "bad format");
194 }
195 return buf;
196}
197
198static inline char *aoc_printf(const char *fmt, char *buf, ...) {
199 va_list ap;
200 va_start(ap, buf);
201 buf = aoc_vprintf(fmt, buf, ap);
202 va_end(ap);
203 return buf;
204}
205
206/* Copy n bytes of text into a malloc'd slice. */
207static inline slice slice_from_text(const char *s, size_t n) {
208 uint8_t *p = malloc(n);
209 aoc_assert(p, "out of memory");
210 if (n) {
211 memcpy(p, s, n);
212 }
213 return (slice){p, n};
214}
215
216/* Decimal text of v, allocated at AOC_I64_TEXT. The minimum
217 * int64_t is not negated. slice.l is the bytes written.
218 */
219static inline slice slice_from_i64(int64_t v) {
220 char tmp[AOC_I64_TEXT];
221 char *d;
222 uint8_t *p;
223 size_t n;
224 d = aoc_printf("%i", tmp, v);
225 n = (size_t)(d - tmp);
226 p = malloc(AOC_I64_TEXT);
227 aoc_assert(p, "out of memory");
228 memcpy(p, tmp, n);
229 return (slice){p, n};
230}
231
232/* Parse one decimal slice into *out. A leading '-' is allowed.
233 * Returns 1 on success, 0 for invalid text or int64_t overflow.
234 */
235static inline int slice_to_i64(slice s, int64_t *out) {
236 size_t i = 0;
237 int neg = 0;
238 uint64_t u = 0;
239 if (!s.p || s.l == 0 || !out) {
240 return 0;
241 }
242 if (s.p[0] == '-') {
243 neg = 1;
244 i = 1;
245 if (s.l == 1) {
246 return 0;
247 }
248 }
249 for (; i < s.l; i++) {
250 uint8_t c = s.p[i];
251 if (c < '0' || c > '9') {
252 return 0;
253 }
254 uint64_t digit = (uint64_t)(c - '0');
255 uint64_t limit = (uint64_t)INT64_MAX + (uint64_t)neg;
256 if (u > (limit - digit) / 10u) {
257 return 0;
258 }
259 u = u * 10u + digit;
260 }
261 if (neg) {
262 *out = u == (uint64_t)INT64_MAX + 1u ? INT64_MIN : -(int64_t)u;
263 } else {
264 *out = (int64_t)u;
265 }
266 return 1;
267}
268
269#endifThe aha moment
There is barely any input to read: just a short secret key. That looks encouraging, until we ask where the answer is supposed to come from. We must append positive integers, hash them, and wait for a digest with the right prefix. The key's length tells us almost nothing about how long that wait will be.
Before pressing Run and wondering whether the program is stuck, estimate the odds. Each hexadecimal digit has sixteen possible values. Under a uniform-prefix model, five leading zeroes occur once in 16⁵ trials on average—about a million hashes. That gives us a useful expectation. A million simple trials is a plausible plan, and trying integers in increasing order means the first hit is automatically the smallest answer.
Could a near miss guide the next guess? Unfortunately, a digest beginning 00001 does not tell us that we are getting closer. Changing the suffix scrambles the digest rather than nudging it toward zero. There is no useful uphill or downhill direction here. This is one of those days when accepting brute force is itself the good decision: the effort belongs in making each trial cheap, not inventing a search heuristic without evidence.
Part 2 says, in effect, just one more zero. Oh. That tiny edit multiplies the expected work by sixteen, to about 16.8 million candidates. The same little input now asks much more of the computer. The estimate is not a deadline, though. The local key's first hits are 254,575 and 1,038,736, so its second part is much luckier than the average. Measuring a real run helps us distinguish a slow implementation from an unusually long wait.
Once the loop is doing millions of trials, small conveniences inside it become expensive. We only need to know whether some leading bits are zero, so formatting every digest as hexadecimal text does unnecessary work. Reuse the key-and-suffix buffer, increment the decimal suffix in place, and rebuild padding when its length changes. The implementation also spells out MD5's fixed rounds to reduce execution-budget overhead. These are satisfying, concrete savings: each guess costs less, while the search still checks every necessary candidate in order.
The solver accepts keys of at most 64 printable characters and tries candidates 1 through 2,000,000. Both measured local answers fit; many other valid keys will not, especially in part 2. Exhausting that allowance is an explicit rejection, not evidence that the key has no answer. The search cap and the deployed CPU limit are separate constraints.
See also
Categories for 2015–2024 adapted from u/Boojum’s 500 Stars: A Categorization and Mega-Guide ↗. A day can belong to several categories. Tags from 2025 onward are our additions.
Try your input
One POST, one reply. Your input is not saved.