Skip to content

Commit 41b8c8e

Browse files
committed
Add scoring on zero bytes anywhere in hash
1 parent 7fa6071 commit 41b8c8e

6 files changed

Lines changed: 32 additions & 4 deletions

File tree

ModeFactory.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ mode ModeFactory::benchmark() {
88
return r;
99
}
1010

11+
mode ModeFactory::zerobytes() {
12+
mode r;
13+
r.function = ModeFunction::ZeroBytes;
14+
return r;
15+
}
16+
1117
mode ModeFactory::zeros() {
1218
return range(0, 0);
1319
}

ModeFactory.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class ModeFactory {
1818
static mode mirror();
1919

2020
static mode benchmark();
21+
static mode zerobytes();
2122
static mode zeros();
2223
static mode letters();
2324
static mode numbers();

eradicate2.cl

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
enum ModeFunction {
2-
Benchmark, Matching, Leading, Range, Mirror, Doubles, LeadingRange
2+
Benchmark, ZeroBytes, Matching, Leading, Range, Mirror, Doubles, LeadingRange
33
};
44

55
typedef struct {
@@ -18,6 +18,7 @@ __kernel void eradicate2_iterate(__global result * const pResult, __global const
1818
void eradicate2_result_update(const uchar * const hash, __global result * const pResult, const uchar score, const uchar scoreMax, const uint deviceIndex, const uint round);
1919
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);
2020
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);
21+
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);
2122
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);
2223
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);
2324
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);
@@ -40,14 +41,18 @@ __kernel void eradicate2_iterate(__global result * const pResult, __global const
4041
sha3_keccakf(&h);
4142

4243
/* enum class ModeFunction {
43-
* Benchmark, Matching, Leading, Range, Mirror, Doubles, LeadingRange
44+
* Benchmark, ZeroBytes, Matching, Leading, Range, Mirror, Doubles, LeadingRange
4445
* };
4546
*/
4647
switch (pMode->function) {
4748
case Benchmark:
4849
eradicate2_score_benchmark(h.b + 12, pResult, pMode, scoreMax, deviceIndex, round);
4950
break;
5051

52+
case ZeroBytes:
53+
eradicate2_score_zerobytes(h.b + 12, pResult, pMode, scoreMax, deviceIndex, round);
54+
break;
55+
5156
case Matching:
5257
eradicate2_score_matching(h.b + 12, pResult, pMode, scoreMax, deviceIndex, round);
5358
break;
@@ -126,6 +131,17 @@ void eradicate2_score_benchmark(const uchar * const hash, __global result * cons
126131
eradicate2_result_update(hash, pResult, score, scoreMax, deviceIndex, round);
127132
}
128133

134+
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) {
135+
const size_t id = get_global_id(0);
136+
int score = 0;
137+
138+
for (int i = 0; i < 20; ++i) {
139+
score += !hash[i];
140+
}
141+
142+
eradicate2_result_update(hash, pResult, score, scoreMax, deviceIndex, round);
143+
}
144+
129145
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) {
130146
const size_t id = get_global_id(0);
131147
int score = 0;

eradicate2.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ int main(int argc, char * * argv) {
179179
ArgParser argp(argc, argv);
180180
bool bHelp = false;
181181
bool bModeBenchmark = false;
182+
bool bModeZeroBytes = false;
182183
bool bModeZeros = false;
183184
bool bModeLetters = false;
184185
bool bModeNumbers = false;
@@ -200,6 +201,7 @@ int main(int argc, char * * argv) {
200201

201202
argp.addSwitch('h', "help", bHelp);
202203
argp.addSwitch('0', "benchmark", bModeBenchmark);
204+
argp.addSwitch('z', "zero-bytes", bModeZeroBytes);
203205
argp.addSwitch('1', "zeros", bModeZeros);
204206
argp.addSwitch('2', "letters", bModeLetters);
205207
argp.addSwitch('3', "numbers", bModeNumbers);
@@ -248,7 +250,9 @@ int main(int argc, char * * argv) {
248250
mode mode = ModeFactory::benchmark();
249251
if (bModeBenchmark) {
250252
mode = ModeFactory::benchmark();
251-
} else if (bModeZeros) {
253+
} else if (bModeZeroBytes) {
254+
mode = ModeFactory::zerobytes();
255+
} else if (bModeZeros) {
252256
mode = ModeFactory::zeros();
253257
} else if (bModeLetters) {
254258
mode = ModeFactory::letters();

help.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ usage: ./ERADICATE2 [OPTIONS]
1919
Basic modes:
2020
--benchmark Run without any scoring, a benchmark.
2121
--zeros Score on zeros anywhere in hash.
22+
--zero-bytes Score on zero bytes anywhere in hash.
2223
--letters Score on letters anywhere in hash.
2324
--numbers Score on numbers anywhere in hash.
2425
--mirror Score on mirroring from center.

types.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#endif
1212

1313
enum class ModeFunction {
14-
Benchmark, Matching, Leading, Range, Mirror, Doubles, LeadingRange
14+
Benchmark, ZeroBytes, Matching, Leading, Range, Mirror, Doubles, LeadingRange
1515
};
1616

1717
typedef struct {

0 commit comments

Comments
 (0)