The Challenge
The binary applies a custom hash: the flag is broken into character positions, and for each position i the hash value is the sum of 7 consecutive characters (wrapping around cyclically). The 50 hash output values are given. The task is to invert this: find 50 character values that produce exactly those sums.
Approach
This is a system of linear equations: each equation says sum(flag[(i + k) % 50] for k in 0..6) == cfhash[i]. With 50 equations and 50 unknowns, Z3 can solve it directly.
Declare 50 integer variables, add one constraint per hash value, call check(), extract the model. The output integers are ASCII codes, so cast them with chr().
The wrapping is handled by (i + e) % len(cfhash) in the constraint loop.
Solution
|
|
Z3 finds integer assignments satisfying all 50 sum constraints simultaneously. The model output for each variable is the ASCII code of the corresponding flag character.
What I Learned
Cyclic windowed sums are a common pattern in custom hash functions. The moment you see a hash where h[i] = sum(plain[i..i+k]) with cyclic indexing, you can set it up as a Z3 integer linear programming problem. Each output hash value becomes one equality constraint.