-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
79 lines (63 loc) · 1.91 KB
/
main.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
package main
import (
"fmt"
"log"
"math/rand"
"os"
"sync"
"time"
"github.com/ethereum/go-ethereum/crypto"
)
// Function to generate a random Ethereum address and private key
func generateAddressAndPrivateKey(wg *sync.WaitGroup, ch chan string) {
defer wg.Done()
// Generate a random 32-byte private key
privateKey, err := crypto.GenerateKey()
if err != nil {
log.Println("Error generating private key:", err)
return
}
// Get the public key from the private key
publicKey := privateKey.PublicKey
// Derive the Ethereum address from the public key
address := crypto.PubkeyToAddress(publicKey)
// Convert private key to bytes (hex representation)
privateKeyBytes := crypto.FromECDSA(privateKey)
// Format the address and private key as "ADDRESS | PRIVATE_KEY"
result := fmt.Sprintf("%s | %s", address.Hex(), fmt.Sprintf("%x", privateKeyBytes))
// Send the result to the channel
ch <- result
}
func main() {
// Set up concurrency
rand.Seed(time.Now().UnixNano()) // Initialize random number generator
var wg sync.WaitGroup
addressCount := 1000 // Change this for how many addresses you want to generate
// Create a channel to collect results (address | private_key)
resultChan := make(chan string, addressCount)
// Start address generation in parallel
for i := 0; i < addressCount; i++ {
wg.Add(1)
go generateAddressAndPrivateKey(&wg, resultChan)
}
// Wait for all goroutines to finish
go func() {
wg.Wait()
close(resultChan)
}()
// Write generated address | private key pairs to file
file, err := os.Create("output/result.txt")
if err != nil {
log.Fatal("Error creating file:", err)
}
defer file.Close()
// Print the results and save them
for result := range resultChan {
_, err := file.WriteString(result + "\n")
if err != nil {
log.Fatal("Error writing to file:", err)
}
fmt.Println(result) // Print to console
}
fmt.Println("Address and Private Key generation complete!")
}