fix: correct convergence logic in hcatFingerprint loop

The old loop reassigned crackedBefore at the top of each iteration and
initialized crackedAfter to 0, which could cause the loop to enter
spuriously or skip entirely. Switch to while True / break to properly
detect when an iteration produces no new cracks.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Justin Bollinger
2026-04-13 10:10:01 -04:00
parent 44489a0ce6
commit 786df786b7
2 changed files with 6 additions and 4 deletions

View File

@@ -1411,9 +1411,7 @@ def hcatFingerprint(
raise ValueError("expander_len must be an integer between 7 and 36")
crackedBefore = lineCount(hcatHashFile + ".out")
crackedAfter = 0
while crackedBefore != crackedAfter:
crackedBefore = lineCount(hcatHashFile + ".out")
while True:
_write_delimited_field(f"{hcatHashFile}.out", f"{hcatHashFile}.working", 2)
expander_bin = (
hcatExpanderBin if expander_len == 7 else f"expander{expander_len}.bin"
@@ -1477,6 +1475,9 @@ def hcatFingerprint(
hcatHybrid(hcatHashType, hcatHashFile, [f"{hcatHashFile}.expanded"])
crackedAfter = lineCount(hcatHashFile + ".out")
if crackedAfter == crackedBefore:
break
crackedBefore = crackedAfter
hcatFingerprintCount = lineCount(hcatHashFile + ".out") - hcatHashCracked

View File

@@ -42,7 +42,8 @@ def test_hcatFingerprint_uses_selected_expander_and_calls_hybrid(monkeypatch, tm
out_path.write_text("deadbeef:Accordbookkeeping2025!:x\n")
# Make the loop run exactly one iteration.
counts = iter([1, 1, 1, 1])
# Calls: before-loop(1), end-of-iteration(1) == before → break, post-loop(1).
counts = iter([1, 1, 1])
monkeypatch.setattr(hc_main, "lineCount", lambda _p: next(counts))
monkeypatch.setattr(hc_main, "hcatHashCracked", 0)