From 4629f994951ba47d5f25f554ea349e230aa214f5 Mon Sep 17 00:00:00 2001 From: modeco80 Date: Tue, 22 Aug 2023 20:06:21 -0400 Subject: [PATCH] implement a basic hash-per-second display --- src/worker.cpp | 17 +++++++++++++++-- src/worker.hpp | 6 ++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/worker.cpp b/src/worker.cpp index eaa0d75..2faea30 100644 --- a/src/worker.cpp +++ b/src/worker.cpp @@ -23,6 +23,7 @@ namespace swbf { std::uint32_t threadIndex; std::string codeString; std::uint32_t codeHash; + std::uint32_t hashRate; bool done = false; /// The matched codes for this thread. @@ -31,8 +32,8 @@ namespace swbf { void DisplayProgress() { if(!done) - swbf::fprint(stdout, "{}Thread {:2}: Trying code {}{} {}({:08x}){}", swbf::ansi::Line(threadIndex), threadIndex, - swbf::ansi::Color(172), codeString, swbf::ansi::Color(166), codeHash, swbf::ansi::Reset()); + swbf::fprint(stdout, "{}Thread {:2}: Trying code {}{} {}({:08x}, {} hps){}", swbf::ansi::Line(threadIndex), threadIndex, + swbf::ansi::Color(172), codeString, swbf::ansi::Color(166), codeHash, hashRate, swbf::ansi::Reset()); else { swbf::fprint(stdout, "{}{}Thread {:2}: {}Finished!{}", swbf::ansi::Line(threadIndex), swbf::ansi::ResetLine(), threadIndex, swbf::ansi::Color(172), swbf::ansi::Reset()); @@ -79,6 +80,8 @@ namespace swbf { /// Public-facing driver function - the thread pool runs this. void BruteforceWorker::Bruteforce(char prefix) { + start = Clock::now(); + if(options.exact) { BruteforceForLength(prefix, options.startLength); } else { @@ -102,16 +105,26 @@ namespace swbf { if(hash == options.targetHash) DisplayData().matches.push_back(test_buffer); + numChecked++; + CopyDisplayData(); if(!NextCode(test_buffer, 1)) break; + + now = Clock::now(); } } void BruteforceWorker::CopyDisplayData() { std::memcpy(DisplayData().codeString.data(), test_buffer.data(), test_buffer.length()); DisplayData().codeHash = hash; + + if(std::chrono::duration_cast(now - start).count() >= 1) { + DisplayData().hashRate = numChecked; + numChecked = 0; + start = Clock::now(); + } } ThreadInfoData& BruteforceWorker::DisplayData() { diff --git a/src/worker.hpp b/src/worker.hpp index c256aaa..56e4416 100644 --- a/src/worker.hpp +++ b/src/worker.hpp @@ -1,6 +1,7 @@ #pragma once #include #include +#include namespace swbf { constexpr static auto MAX_CODE_LENGTH = 8; @@ -39,6 +40,11 @@ namespace swbf { unsigned threadIndex; std::string test_buffer; std::uint32_t hash; + + using Clock = std::chrono::steady_clock; + Clock::time_point now; + Clock::time_point start; + std::uint32_t numChecked; }; /// returns true when all threads finished