forked from rebryk/profanity-brute-force
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mode.cpp
199 lines (162 loc) · 4.3 KB
/
Mode.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#include "Mode.hpp"
#include <stdexcept>
#include <iostream>
#include <cassert>
using namespace std;
Mode::Mode() : score(0) {
}
Mode Mode::benchmark() {
Mode r;
r.name = "benchmark";
r.kernel = "profanity_score_benchmark";
return r;
}
Mode Mode::zeros() {
Mode r = range(0, 0);
r.name = "zeros";
return r;
}
static std::string::size_type hexValueNoException(char c) {
if (c >= 'A' && c <= 'F') {
c -= 'A' - 'a';
}
const std::string hex = "0123456789abcdef";
const std::string::size_type ret = hex.find(c);
return ret;
}
static std::string::size_type hexValue(char c) {
const std::string::size_type ret = hexValueNoException(c);
if(ret == std::string::npos) {
throw std::runtime_error("bad hex value");
}
return ret;
}
static unsigned int parseHex(const std::string& strHex) {
assert(strHex.size() == 8);
unsigned int ret = 0;
for (std::string::size_type i = 0; i < strHex.size(); ++i) {
ret <<= 4;
ret |= hexValue(strHex[i]);
}
return ret;
}
static mp_number parseCoordinate(const std::string& strHex) {
assert (strHex.size() == 64);
mp_number c;
for (size_t w = 0; w < 8; ++w) {
const std::string word = strHex.substr(w * 8, 8);
c.d[MP_NWORDS - 1 - w] = parseHex(word);
}
return c;
}
Mode Mode::reverse(const std::string strPublicAddress, const int steps, const bool extented, const bool cache, const int skipX, const int skipY, const bool single) {
Mode r;
r.name = "reverse";
r.kernel = "profanity_score_reverse";
assert(strPublicAddress.size() == 130);
r.targetAddress.x = parseCoordinate(strPublicAddress.substr(2, 64));
r.targetAddress.y = parseCoordinate(strPublicAddress.substr(66, 64));
r.steps = steps;
r.extended = extented;
r.cache = cache;
r.skipX = skipX;
r.skipY = skipY;
r.single = single;
return r;
}
Mode Mode::hashTable(const bool extented, const int skipY) {
Mode r;
r.name = "hashTable";
r.kernel = "profanity_score_reverse";
r.extended = extented;
r.cache = false;
r.skipX = 0;
r.skipY = skipY;
r.single = false;
return r;
}
Mode Mode::matching(const std::string strHex) {
Mode r;
r.name = "matching";
r.kernel = "profanity_score_matching";
std::fill( r.data1, r.data1 + sizeof(r.data1), cl_uchar(0) );
std::fill( r.data2, r.data2 + sizeof(r.data2), cl_uchar(0) );
auto index = 0;
for( size_t i = 0; i < strHex.size(); i += 2 ) {
const auto indexHi = hexValueNoException(strHex[i]);
const auto indexLo = i + 1 < strHex.size() ? hexValueNoException(strHex[i+1]) : std::string::npos;
const auto valHi = (indexHi == std::string::npos) ? 0 : indexHi << 4;
const auto valLo = (indexLo == std::string::npos) ? 0 : indexLo;
const auto maskHi = (indexHi == std::string::npos) ? 0 : 0xF << 4;
const auto maskLo = (indexLo == std::string::npos) ? 0 : 0xF;
r.data1[index] = maskHi | maskLo;
r.data2[index] = valHi | valLo;
++index;
}
return r;
}
Mode Mode::leading(const char charLeading) {
Mode r;
r.name = "leading";
r.kernel = "profanity_score_leading";
r.data1[0] = static_cast<cl_uchar>(hexValue(charLeading));
return r;
}
Mode Mode::range(const cl_uchar min, const cl_uchar max) {
Mode r;
r.name = "range";
r.kernel = "profanity_score_range";
r.data1[0] = min;
r.data2[0] = max;
return r;
}
Mode Mode::letters() {
Mode r = range(10, 15);
r.name = "letters";
return r;
}
Mode Mode::numbers() {
Mode r = range(0, 9);
r.name = "numbers";
return r;
}
std::string Mode::transformKernel() const {
switch (this->target) {
case ADDRESS:
return "";
case CONTRACT:
return "profanity_transform_contract";
default:
throw "No kernel for target";
}
}
std::string Mode::transformName() const {
switch (this->target) {
case ADDRESS:
return "Address";
case CONTRACT:
return "Contract";
default:
throw "No name for target";
}
}
Mode Mode::leadingRange(const cl_uchar min, const cl_uchar max) {
Mode r;
r.name = "leadingrange";
r.kernel = "profanity_score_leadingrange";
r.data1[0] = min;
r.data2[0] = max;
return r;
}
Mode Mode::mirror() {
Mode r;
r.name = "mirror";
r.kernel = "profanity_score_mirror";
return r;
}
Mode Mode::doubles() {
Mode r;
r.name = "doubles";
r.kernel = "profanity_score_doubles";
return r;
}