-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4.cpp
More file actions
65 lines (44 loc) · 1.43 KB
/
4.cpp
File metadata and controls
65 lines (44 loc) · 1.43 KB
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
#include <iostream>
#include <openssl/md5.h>
#define MD5_DIGEST_LENGTH 16
static const char hexchars[] = "0123456789abcdef";
std::string convertDigestToHexString(unsigned char * digest) {
std::string result;
for (int i = 0; i < MD5_DIGEST_LENGTH; i++) {
unsigned char elem = digest[i];
char hex[3];
hex[0] = hexchars[elem >> 4];
hex[1] = hexchars[elem & 0xF];
hex[2] = 0;
result.append(hex);
}
return result;
}
bool hasFiveZeroes(unsigned char * digest) {
unsigned char testNumber[16] = {0xFF, 0xFF, 0xF0, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00};
unsigned char andResult = 0;
for (int j = 0; j < MD5_DIGEST_LENGTH; j++) {
andResult = testNumber[j] & digest[j];
if (andResult) return false;
}
return true;
}
int main(void) {
std::string key = "ckczppom";
std::string data;
unsigned int i = 0;
bool _hasFiveZeroes = false;
unsigned char * digest;
while (!_hasFiveZeroes) {
data = key + std::to_string(i);
digest = MD5((const unsigned char *)data.c_str(), data.size(), NULL);
_hasFiveZeroes = hasFiveZeroes(digest);
++i;
}
std::string result = convertDigestToHexString(digest);
std::cout << i-1 << " data: " << data << " result:" << result << std::endl;
std::cout << "has 5 zeroes: " << _hasFiveZeroes << std::endl;
}