main.go
TEXT FILE659 B · Public source code for developers, search crawlers and AI agents
1package main
2
3import (
4 "crypto/rand"
5 "encoding/hex"
6 "fmt"
7 "math/big"
8)
9
10var order, _ = new(big.Int).SetString("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", 16)
11
12func valid(b []byte) bool {
13 return len(b) == 32 && new(big.Int).SetBytes(b).Sign() > 0 && new(big.Int).SetBytes(b).Cmp(order) < 0
14}
15func generate() ([]byte, error) {
16 n, e := rand.Int(rand.Reader, new(big.Int).Sub(order, big.NewInt(1)))
17 if e != nil {
18 return nil, e
19 }
20 return n.Add(n, big.NewInt(1)).FillBytes(make([]byte, 32)), nil
21}
22func main() {
23 b, _ := hex.DecodeString("0000000000000000000000000000000000000000000000000000000000000001")
24 fmt.Println(valid(b))
25}Read-only source · Select a line number to link directly · Raw download above
