Simple Maze the solution path is text

misc
flag d4rk{hollows_the_maze}

d4rk{hollows_the_maze}

d4rkmaze.png: a perfect maze whose unique solution path spells text

Summary

d4rkmaze.png (3120×507 RGB) is a perfect maze whose unique solution path, when drawn, traces block letters. The maze body is 258×37 cells of 12 px; the grid lines sit at x = 11+12k and y = 11+12k. Because the maze is a spanning tree (9546 cells, 9545 open passages, a single connected component), the path between the two border openings is the path — there is no search ambiguity. Solving it with BFS and rendering the cell-centre polyline without the walls makes the letters legible, and the flag is the text under the image. The initial read of the rendered path was corrected after zooming: the letters are D4RK HOW WAS THE MAZE, not D4RK HOLLOWS THE MAZE (the two words "HOW WAS" had collapsed into one group). Spaces become underscores inside the braces.

Solution / Exploit

1. Grid and wall extraction (parse.py)

Threshold at gray < 128; grid lines at x = 11+12k (258 columns) and y = 11+12k (37 rows) → 12 px cells, maze body 258×37. Walls are sampled 7 px along each 12-px edge at the grid line; an edge is a wall if ≥50% of the samples are dark.

python
1from PIL import Image
2import numpy as np
3im = Image.open('d4rkmaze.png').convert('L')
4a = np.array(im); dark = a < 128
5X0, Y0, S = 11, 11, 12
6NC = (3107-11)//12   # 258
7NR = (455-11)//12    # 37
8print('grid', NC, 'x', NR)
9
10def seg_dark_frac(x1,y1,x2,y2,n=7):
11    xs = np.linspace(x1,x2,n).astype(int)
12    ys = np.linspace(y1,y2,n).astype(int)
13    return dark[ys,xs].mean()
14
15def hwall(c,r):                    # horizontal wall on north side of row r, col c
16    y = Y0+S*r
17    return seg_dark_frac(X0+S*c+2, y, X0+S*(c+1)-2, y, 7) > 0.5
18def vwall(c,r):                    # vertical wall on west side of row r, col c
19    x = X0+S*c
20    return seg_dark_frac(x, Y0+S*r+2, x, Y0+S*(r+1)-2, 7) > 0.5
21
22H = np.zeros((NR+1, NC), dtype=bool)   # H[r][c] = wall on north side of cell (r,c)
23V = np.zeros((NR, NC+1), dtype=bool)   # V[r][c] = wall on west side of cell (r,c)
24for r in range(NR+1):
25    for c in range(NC):
26        H[r,c] = hwall(c,r)
27for r in range(NR):
28    for c in range(NC+1):
29        V[r,c] = vwall(c,r)
30np.save('simplemaze_work/H.npy', H); np.save('simplemaze_work/V.npy', V)
31print('H wall frac', H.mean(), 'V wall frac', V.mean())

Border openings are only at the bottom-left (START, row 36 col 0) and bottom-right (FINISH, row 36 col 257); no other border edge is open.

2. Solve with BFS (solve.py)

BFS from (36,0) to (36,257) gives 2235 moves. Edge count == nodes−1, i.e. the maze is a spanning tree, so this path is unique.

python
1import numpy as np
2from collections import deque
3H = np.load('simplemaze_work/H.npy'); V = np.load('simplemaze_work/V.npy')
4NR, NC = 37, 258
5start=(36,0); goal=(36,257)
6prev={start:None}
7q=deque([start])
8while q:
9    r,c=q.popleft()
10    if (r,c)==goal: break
11    for (nr,nc,wall) in ((r-1,c,H[r,c]),(r+1,c,H[r+1,c]),(r,c-1,V[r,c]),(r,c+1,V[r,c+1])):
12        if 0<=nr<NR and 0<=nc<NC and not wall and (nr,nc) not in prev:
13            prev[(nr,nc)]=(r,c); q.append((nr,nc))
14path=[]; cur=goal
15while cur: path.append(cur); cur=prev[cur]
16path.reverse()
17print('path length (cells):', len(path))
18print('reachable cells:', len(prev), 'of', NR*NC)
19dirs=[]
20for (r1,c1),(r2,c2) in zip(path,path[1:]):
21    if   r2==r1-1: dirs.append('U')
22    elif r2==r1+1: dirs.append('D')
23    elif c2==c1-1: dirs.append('L')
24    else:          dirs.append('R')
25s=''.join(dirs)
26print('dir string len', len(s))
27open('simplemaze_work/dirs.txt','w').write(s)

The 2235-move direction string begins:

output
RRULLUUURURUUURDDRDRURRULULURURDRDRURUURRUULURUUUUUUULURUULURRRRURDRRRDDRRDRDLDDDDRDLDDLLDDLDLULLLURRRRUURRUUULURUUULLUULLDLULLDDDDRDLDDRDLDDDDDRRDRDDDDRUURURDDRURRUURDRRUURDDDDDDRUURRDDRUUURURUUUULURUUUULLLLLLLDLUULURUUULURURDRDLDDDDRRRRURDRRUULURUUURDRDLDDDRDLDDDDDRDLDDRDDRUURUUUULURUUUUUUUUUURDRR

3. Read the letters

Render the cell-centre polyline with the walls removed (path_solid.png thickens it so the strokes merge). The path traces the block letters D4RK HOW WAS THE MAZE; the per-word zoom crops (word_w1..w4.png, zcheck_how.png, zcheck_maze.png) confirm the ambiguous groups: HOW (the O is a closed box, not a Q) and the final word MAZE.

4. Format

The text under the image gives the flag format: d4rk{...}, words joined by _, per the example `d4rk hello world` is `d4rk{hello_world}`. First word d4rk is the prefix, the rest lower-cased and _-joined:

output
d4rk{how_was_the_maze}

Flag(s)

output
d4rk{how_was_the_maze}

Alternates

  • d4rk{hollows_the_maze} — the earlier, superseded reading. The first pass rendered the path correctly but misread the glyphs as D4RK HOLLOWS THE MAZE, collapsing the two words "HOW WAS" into one group. Re-reading the rendered solid path and zooming the ambiguous groups (zcheck_how.png, zcheck_maze.png) gives D4RK HOW WAS THE MAZE.
  • d4rk{HOLLOWS_THE_MAZE} — the uppercase variant of the same superseded reading, i.e. what the in-image regex d4rk{^[A-Z]+$} would imply if the letters were taken literally and uppercase.
  • d4rk{^[A-Z]+$} — not a flag: this is the regex format hint printed in the image. It is self-inconsistent with the worked example (uppercase vs lowercase); the example is the concrete input→output rule and every other flag in the event is lowercase, so lowercase was chosen. No submission was available (event over) to disambiguate.
  • d4rk{quantum_echo_reuse_breaks_the_pad} — not a flag of this challenge: another h4ckc0n challenge's flag, cited only as an example of the event's lowercase convention.

Notes / Pitfalls

  • Perfect maze ⇒ unique path. 9546 cells with 9545 open passages and one connected component means the maze is a spanning tree, so the BFS path is not one of several — it is the path. That is what makes "the path is the message" well defined.
  • Reading the glyphs is the hard part, not solving the maze. The BFS is trivial; the failure mode is misreading the rendered strokes. The first read produced HOLLOWS THE MAZE; only zooming the ambiguous groups revealed HOW WAS THE MAZE.
  • Case ambiguity in the hint. The in-image regex ^[A-Z]+$ contradicts the lowercase example. Resolved in favour of the example (and the rest of the event's flags).
  • Artifacts. Proof images live in simplemaze_work/: path_overlay.png (path in red over the maze), path_solid.png (thickened path = readable text), path_seg0..4.png, word_w1..w4.png, zcheck_how.png, zcheck_maze.png, dirs.txt (the 2235-move direction string), and parse.py + solve.py.