Bitcoin Forum
June 24, 2024, 03:31:36 AM *
News: Voting for pizza day contest
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: golang to c  (Read 75 times)
Kostelooscoin (OP)
Member
**
Offline Offline

Activity: 205
Merit: 16


View Profile
February 11, 2021, 07:10:30 PM
 #1

good evening would it be possible to convert this golang code into c

Code:
package main

import (
"fmt"
"math/big"
"strings"
"crypto/rand"

"github.com/btcsuite/btcutil"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/chaincfg"
)

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")

// Create a slice to pad our count to 32 bytes
padded := make([]byte, 32)

// Loop forever because we're never going to hit the end anyway
for {
min, ok := new(big.Int).SetString(
"251348912559107511842248025991027577915370614295322973614803128542477733180",
10,
)
if !ok {
return
}
max, ok := new(big.Int).SetString(
"251348912559107511842248025991027577915370614295322973614803128574666213685",
10,
)
if !ok {
return
}
r, err := randInt(min, max)
if err != nil {
return
}
// Copy count value's bytes to padded slice
copy(padded[32-len(r.Bytes()):], r.Bytes())

// Get public key
_, public := btcec.PrivKeyFromBytes(btcec.S256(), padded)

// Get compressed and uncompressed addresses
caddr, _ := btcutil.NewAddressPubKey(public.SerializeCompressed(), &chaincfg.MainNetParams)

// Print keys
if strings.HasPrefix(caddr.EncodeAddress(), "1Jomfp") {
fmt.Printf("%x %34s\n", padded, caddr.EncodeAddress())
}
}
}

NotATether
Legendary
*
Offline Offline

Activity: 1638
Merit: 6911


bitcoincleanup.com / bitmixlist.org


View Profile WWW
February 11, 2021, 09:06:20 PM
 #2

Now I'm usually helpful for for solving problems like this but did you actually attempt to rewrite it yourself before you posted it on the forum for help? When you ask a question like "I have code in xyz programming language, can someone please write it in foobarbaz language?" you're giving off the impression that you don't want to do it and are hoping that somebody else will do it for you. If this is truly the case and you want somebody else to convert this code then make a thread in the Marketplace board and pay someone to do it there.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!