replace printing code with somehting hopefully better?
This commit is contained in:
parent
ff97f2855e
commit
22c61ea451
46
src/main.cpp
46
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,20 +95,42 @@ 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) {
|
||||||
//for(std::uint32_t i = 8; i <= code_length; ++i) {
|
// for(std::uint32_t i = 8; i <= code_length; ++i) {
|
||||||
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);
|
||||||
auto hash = SwsfScramble(test_buffer);
|
auto hash = SwsfScramble(test_buffer);
|
||||||
if( hash == code_hash) {
|
if(hash == code_hash) {
|
||||||
std::cerr << std::format("match: {} ({:08x})\n", test_buffer, hash);
|
std::cerr << std::format("match: {} ({:08x})\n", test_buffer, hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +145,7 @@ struct BruteThreadState {
|
||||||
private:
|
private:
|
||||||
unsigned line;
|
unsigned line;
|
||||||
std::random_device rd;
|
std::random_device rd;
|
||||||
//swbf::Xoshiro256ss rng{rd};
|
// swbf::Xoshiro256ss rng{rd};
|
||||||
};
|
};
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
Loading…
Reference in New Issue