forked from SvenMeyer/privatekey2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex_test.js
58 lines (44 loc) · 1.57 KB
/
index_test.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
const public_address = 'af7560c61fc7d3d4404e8403b7b9194d62d7be2e'.toLowerCase();
const pk = '3334057ece90ab38e401718737636c4ebb8c623f82382c6aa53c309bf0d6ec62';
const ethers = require('ethers')
let w = new ethers.Wallet(pk)
try {
w = new ethers.Wallet(pk)
console.log(w)
w_address = w.signingKey.address
console.log("address =", w_address)
}
catch (e) {
console.log('Invalid private key.')
}
// -----------------------------------------------------------
const ethereumjsWallet = require('ethereumjs-wallet')
var r
var pk_buf = Buffer.from(pk, 'hex');
console.log({pk_buf})
r = ethereumjsWallet.fromPrivateKey(pk_buf)
console.log("result = ", r)
console.log("result = ", r.getAddress().toString('hex'))
console.log("result = ", r.getPrivateKey().toString('hex'))
// -----------------------------------------------------------
const start = Date.now();
var result
const public_address_buf = Buffer.from(public_address, 'hex');
console.log("public_address_buf :", public_address_buf)
for (let x = 0; x < 256; x++) {
pk_buf[0] = x;
for (let y = 0; y < 256; y++) {
pk_buf[1] = y;
r = ethereumjsWallet.fromPrivateKey(pk_buf)
// w_address = r.getAddress().toString('hex')
// if (w_address == public_address) {
if (public_address_buf.compare(r.getAddress()) == 0) {
console.log("found matching addess")
console.log("public address :", w_address)
console.log("Public Key :", r.getPublicKey().toString('hex'))
console.log("private key :", r.getPrivateKey().toString('hex'))
// exit
}
}
}
console.log("processing time =", (Date.now() - start)/1000, "sec")