replace printing code with somehting hopefully better?
This commit is contained in:
parent
ff97f2855e
commit
22c61ea451
38
src/main.cpp
38
src/main.cpp
|
@ -34,19 +34,19 @@ std::string RandomString(std::uint32_t length, TRandomAlgo& rng) {
|
||||||
constexpr std::uint32_t SwsfScramble(std::string_view code) {
|
constexpr std::uint32_t SwsfScramble(std::string_view code) {
|
||||||
std::uint32_t tally {};
|
std::uint32_t tally {};
|
||||||
|
|
||||||
auto cycle = [&tally](char c) {
|
auto cycle = [&tally](char c) { tally = c + (tally * 5); };
|
||||||
tally = c + (tally * 5);
|
|
||||||
};
|
|
||||||
|
|
||||||
cycle('c'); cycle('o'); cycle('d'); cycle('e'); cycle('_');
|
cycle('c');
|
||||||
|
cycle('o');
|
||||||
|
cycle('d');
|
||||||
|
cycle('e');
|
||||||
|
cycle('_');
|
||||||
|
|
||||||
for(auto* p = code.data(); *p; ++p)
|
for(auto* p = code.data(); *p; ++p)
|
||||||
cycle(tolower(*p));
|
cycle(tolower(*p));
|
||||||
return tally;
|
return tally;
|
||||||
}
|
}
|
||||||
|
|
||||||
// using ChannelType = concurrent_channel<void(std::string& codeMatch)>;
|
|
||||||
|
|
||||||
// These is not atomic since no other threads update it
|
// These is not atomic since no other threads update it
|
||||||
// there is no real point to making it atomic, other than
|
// there is no real point to making it atomic, other than
|
||||||
//
|
//
|
||||||
|
@ -95,7 +95,30 @@ struct BruteThreadState {
|
||||||
|
|
||||||
void DisplayProgress(const std::string& code, std::uint32_t hash) {
|
void DisplayProgress(const std::string& code, std::uint32_t hash) {
|
||||||
std::lock_guard<std::mutex> lk(print_lock);
|
std::lock_guard<std::mutex> lk(print_lock);
|
||||||
std::cout << Line(line) << std::format("Thread {:2}: Trying code {}{} {}({:08x}){}", line, Color(172), code, Color(166), hash, Reset()) << std::flush;
|
struct FputcIterator {
|
||||||
|
using iterator_category = std::output_iterator_tag;
|
||||||
|
using value_type = void;
|
||||||
|
using difference_type = std::ptrdiff_t;
|
||||||
|
using pointer = void;
|
||||||
|
using reference = void;
|
||||||
|
|
||||||
|
FputcIterator(std::FILE* file) : file(file) {}
|
||||||
|
FputcIterator& operator*() { return *this; }
|
||||||
|
FputcIterator& operator++() { return *this; }
|
||||||
|
FputcIterator& operator++(int) { return *this; }
|
||||||
|
|
||||||
|
FputcIterator& operator=(const char& val) {
|
||||||
|
fputc(val, file);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::FILE* file;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::format_to(FputcIterator(stdout), "{}Thread {:2}: Trying code {}{} {}({:08x}){}", Line(line), line, Color(172), code, Color(166), hash,
|
||||||
|
Reset());
|
||||||
|
std::fflush(stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BruteForce(char prefix) {
|
void BruteForce(char prefix) {
|
||||||
|
@ -103,7 +126,6 @@ struct BruteThreadState {
|
||||||
std::string test_buffer(code_length, 'a');
|
std::string test_buffer(code_length, 'a');
|
||||||
test_buffer[0] = prefix;
|
test_buffer[0] = prefix;
|
||||||
|
|
||||||
|
|
||||||
// test all possible combinations
|
// test all possible combinations
|
||||||
while(true) {
|
while(true) {
|
||||||
// std::string test_buffer = RandomString(code_length, rng);
|
// std::string test_buffer = RandomString(code_length, rng);
|
||||||
|
|
Loading…
Reference in New Issue