forked from SvenMeyer/privatekey2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
69 lines (51 loc) · 1.89 KB
/
index.js
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
// https://ethereum.stackexchange.com/questions/1771/how-to-validate-a-private-key
const private_key = '3334057ece90ab38e401718737636c4ebb8c623f82382c6aa53c309bf0d6ec62';
var pk = '3334057ece90ab38e401718737636c4ebb8c623f82382c6aa53c309bf0';
var public_address = 'af7560c61fc7d3d4404e8403b7b9194d62d7be2e'.toLowerCase();
if (process.argv.length == 4) {
public_address = process.argv[2].toLowerCase();
pk = process.argv[3];
}
if (public_address.length != 40) {
throw("ERROR : input parameter public address is not 40 digits. Length = " + public_address.length)
}
if (pk.length > 64) {
throw("ERROR : input parameter private key is longer than 64 digits. Length = " + pk.length)
}
if (pk.length < 58) {
throw("ERROR : input parameter private key is shorter than 58 digits. Length = " + pk.length)
}
pk = pk.padEnd(64,'0');
console.log("public_address :", public_address)
console.log("private_key :", pk)
const secp256k1 = require('secp256k1')
const ethereumjsWallet = require('ethereumjs-wallet')
var r
var pk_buf = Buffer.from(pk, 'hex');
const start = Date.now();
const public_address_buf = Buffer.from(public_address, 'hex');
console.log("public_address_buf :", public_address_buf)
var n=0;
for (let x = 255; x >= 0; x--) {
pk_buf[29] = x;
console.log(x , pk_buf)
for (let y = 255; y >= 0; y--) {
pk_buf[30] = y;
for (let z = 255; z >= 0; z--) {
pk_buf[31] = z;
r = ethereumjsWallet.fromPrivateKey(pk_buf)
n++;
if (public_address_buf.compare(r.getAddress()) == 0) {
console.log("found matching addess")
console.log("public address :", r.getAddress().toString('hex'))
// console.log("Public Key :", r.getPublicKey().toString('hex'))
console.log("private key :", r.getPrivateKey().toString('hex'))
console.log(n , " combinations tested");
x = -1;
y = -1;
z = -1;
}
}
}
}
console.log("processing time =", (Date.now() - start)/1000, "sec")