Skip to content

Commit

Permalink
Add scoring on zero bytes anywhere in hash
Browse files Browse the repository at this point in the history
  • Loading branch information
johguse committed May 27, 2020
1 parent 7fa6071 commit 41b8c8e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 4 deletions.
6 changes: 6 additions & 0 deletions ModeFactory.cpp
Expand Up @@ -8,6 +8,12 @@ mode ModeFactory::benchmark() {
return r;
}

mode ModeFactory::zerobytes() {
mode r;
r.function = ModeFunction::ZeroBytes;
return r;
}

mode ModeFactory::zeros() {
return range(0, 0);
}
Expand Down
1 change: 1 addition & 0 deletions ModeFactory.hpp
Expand Up @@ -18,6 +18,7 @@ class ModeFactory {
static mode mirror();

static mode benchmark();
static mode zerobytes();
static mode zeros();
static mode letters();
static mode numbers();
Expand Down
20 changes: 18 additions & 2 deletions eradicate2.cl
@@ -1,5 +1,5 @@
enum ModeFunction {
Benchmark, Matching, Leading, Range, Mirror, Doubles, LeadingRange
Benchmark, ZeroBytes, Matching, Leading, Range, Mirror, Doubles, LeadingRange
};

typedef struct {
Expand All @@ -18,6 +18,7 @@ __kernel void eradicate2_iterate(__global result * const pResult, __global const
void eradicate2_result_update(const uchar * const hash, __global result * const pResult, const uchar score, const uchar scoreMax, const uint deviceIndex, const uint round);
void eradicate2_score_leading(const uchar * const hash, __global result * const pResult, __global const mode * const pMode, const uchar scoreMax, const uint deviceIndex, const uint round);
void eradicate2_score_benchmark(const uchar * const hash, __global result * const pResult, __global const mode * const pMode, const uchar scoreMax, const uint deviceIndex, const uint round);
void eradicate2_score_zerobytes(const uchar * const hash, __global result * const pResult, __global const mode * const pMode, const uchar scoreMax, const uint deviceIndex, const uint round);
void eradicate2_score_matching(const uchar * const hash, __global result * const pResult, __global const mode * const pMode, const uchar scoreMax, const uint deviceIndex, const uint round);
void eradicate2_score_range(const uchar * const hash, __global result * const pResult, __global const mode * const pMode, const uchar scoreMax, const uint deviceIndex, const uint round);
void eradicate2_score_leadingrange(const uchar * const hash, __global result * const pResult, __global const mode * const pMode, const uchar scoreMax, const uint deviceIndex, const uint round);
Expand All @@ -40,14 +41,18 @@ __kernel void eradicate2_iterate(__global result * const pResult, __global const
sha3_keccakf(&h);

/* enum class ModeFunction {
* Benchmark, Matching, Leading, Range, Mirror, Doubles, LeadingRange
* Benchmark, ZeroBytes, Matching, Leading, Range, Mirror, Doubles, LeadingRange
* };
*/
switch (pMode->function) {
case Benchmark:
eradicate2_score_benchmark(h.b + 12, pResult, pMode, scoreMax, deviceIndex, round);
break;

case ZeroBytes:
eradicate2_score_zerobytes(h.b + 12, pResult, pMode, scoreMax, deviceIndex, round);
break;

case Matching:
eradicate2_score_matching(h.b + 12, pResult, pMode, scoreMax, deviceIndex, round);
break;
Expand Down Expand Up @@ -126,6 +131,17 @@ void eradicate2_score_benchmark(const uchar * const hash, __global result * cons
eradicate2_result_update(hash, pResult, score, scoreMax, deviceIndex, round);
}

void eradicate2_score_zerobytes(const uchar * const hash, __global result * const pResult, __global const mode * const pMode, const uchar scoreMax, const uint deviceIndex, const uint round) {
const size_t id = get_global_id(0);
int score = 0;

for (int i = 0; i < 20; ++i) {
score += !hash[i];
}

eradicate2_result_update(hash, pResult, score, scoreMax, deviceIndex, round);
}

void eradicate2_score_matching(const uchar * const hash, __global result * const pResult, __global const mode * const pMode, const uchar scoreMax, const uint deviceIndex, const uint round) {
const size_t id = get_global_id(0);
int score = 0;
Expand Down
6 changes: 5 additions & 1 deletion eradicate2.cpp
Expand Up @@ -179,6 +179,7 @@ int main(int argc, char * * argv) {
ArgParser argp(argc, argv);
bool bHelp = false;
bool bModeBenchmark = false;
bool bModeZeroBytes = false;
bool bModeZeros = false;
bool bModeLetters = false;
bool bModeNumbers = false;
Expand All @@ -200,6 +201,7 @@ int main(int argc, char * * argv) {

argp.addSwitch('h', "help", bHelp);
argp.addSwitch('0', "benchmark", bModeBenchmark);
argp.addSwitch('z', "zero-bytes", bModeZeroBytes);
argp.addSwitch('1', "zeros", bModeZeros);
argp.addSwitch('2', "letters", bModeLetters);
argp.addSwitch('3', "numbers", bModeNumbers);
Expand Down Expand Up @@ -248,7 +250,9 @@ int main(int argc, char * * argv) {
mode mode = ModeFactory::benchmark();
if (bModeBenchmark) {
mode = ModeFactory::benchmark();
} else if (bModeZeros) {
} else if (bModeZeroBytes) {
mode = ModeFactory::zerobytes();
} else if (bModeZeros) {
mode = ModeFactory::zeros();
} else if (bModeLetters) {
mode = ModeFactory::letters();
Expand Down
1 change: 1 addition & 0 deletions help.hpp
Expand Up @@ -19,6 +19,7 @@ usage: ./ERADICATE2 [OPTIONS]
Basic modes:
--benchmark Run without any scoring, a benchmark.
--zeros Score on zeros anywhere in hash.
--zero-bytes Score on zero bytes anywhere in hash.
--letters Score on letters anywhere in hash.
--numbers Score on numbers anywhere in hash.
--mirror Score on mirroring from center.
Expand Down
2 changes: 1 addition & 1 deletion types.hpp
Expand Up @@ -11,7 +11,7 @@
#endif

enum class ModeFunction {
Benchmark, Matching, Leading, Range, Mirror, Doubles, LeadingRange
Benchmark, ZeroBytes, Matching, Leading, Range, Mirror, Doubles, LeadingRange
};

typedef struct {
Expand Down

0 comments on commit 41b8c8e

Please sign in to comment.