-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate2.go
102 lines (88 loc) · 2.34 KB
/
generate2.go
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
package main
import (
"fmt"
"math/big"
"net/http"
"io/ioutil"
"os"
//"crypto/sha256"
"crypto/rand"
"strings"
"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/chaincfg"
)
func getbalance(address string) string {
response, err := http.Get("https://blockchain.info/q/getreceivedbyaddress/" + address)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
}
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Printf("%s", err)
os.Exit(1)
}
return string(contents)
}
func randInt(min, max *big.Int) (*big.Int, error) {
if min.Cmp(max) > 0 {
min, max = max, min
}
intvl := new(big.Int)
intvl.Add(intvl.Sub(max, min), big.NewInt(1))
r, err := rand.Int(rand.Reader, intvl)
if err != nil {
return nil, err
}
r.Add(r, min)
return r, nil
}
func main() {
// Print header
fmt.Printf("%64s %34s %34s\n", "Private", "Public", "Public Compressed")
// Initialise big numbers with small numbers
// Create a slice to pad our count to 32 bytes
padded := make([]byte, 32)
//rand.Read(padded)
// Loop forever because we're never going to hit the end anyway
for {
min, ok := new(big.Int).SetString(
"9223372036854775808",
10,
)
if !ok {
return
}
max, ok := new(big.Int).SetString(
"18446744073709551615",
10,
)
if !ok {
return
}
r, err := randInt(min, max)
if err != nil {
return
}
// Increment our counter
//r.Add(r, min)
// Copy count value's bytes to padded slice
copy(padded[32-len(r.Bytes()):], r.Bytes())
// Get private and public keys
//h := sha256.New()
//h.Write(padded[:])
//_, public := btcec.PrivKeyFromBytes(btcec.S256(), h.Sum(nil))
_, public := btcec.PrivKeyFromBytes(btcec.S256(), padded)
// Get compressed and uncompressed addresses
caddr, _ := btcutil.NewAddressPubKey(public.SerializeCompressed(), &chaincfg.MainNetParams)
uaddr, _ := btcutil.NewAddressPubKey(public.SerializeUncompressed(), &chaincfg.MainNetParams)
// Print keys
balanceu := getbalance(uaddr.EncodeAddress())
balancec := getbalance(caddr.EncodeAddress())
if strings.HasPrefix(caddr.EncodeAddress(), "16jY7") {
fmt.Printf("%x %34s %1s %34s %1s\n", padded, uaddr.EncodeAddress(), balanceu, caddr.EncodeAddress(), balancec)
}
}
}