implement a basic hash-per-second display
This commit is contained in:
parent
e8cdc4e41a
commit
4629f99495
|
@ -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<std::chrono::seconds>(now - start).count() >= 1) {
|
||||
DisplayData().hashRate = numChecked;
|
||||
numChecked = 0;
|
||||
start = Clock::now();
|
||||
}
|
||||
}
|
||||
|
||||
ThreadInfoData& BruteforceWorker::DisplayData() {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue