From 786df786b7d3761ccff1a2eb414481e56165d76e Mon Sep 17 00:00:00 2001 From: Justin Bollinger Date: Mon, 13 Apr 2026 10:10:01 -0400 Subject: [PATCH] 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) --- hate_crack/main.py | 7 ++++--- tests/test_fingerprint_expander_and_hybrid.py | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/hate_crack/main.py b/hate_crack/main.py index b2f9040..6242794 100755 --- a/hate_crack/main.py +++ b/hate_crack/main.py @@ -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 diff --git a/tests/test_fingerprint_expander_and_hybrid.py b/tests/test_fingerprint_expander_and_hybrid.py index e4700da..e1b2bd0 100644 --- a/tests/test_fingerprint_expander_and_hybrid.py +++ b/tests/test_fingerprint_expander_and_hybrid.py @@ -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)