Sha256: 7359c01cd5cadec5249dbc08b90093a8ce0a832f8b3e48d885617d8a11494073

Contents?: true

Size: 648 Bytes

Versions: 177

Compression:

Stored size: 648 Bytes

Contents

package diffiehellman

import (
	"math/big"
	"math/rand"
	"time"
)

const testVersion = 1

var r = rand.New(rand.NewSource(time.Now().Unix()))
var two = big.NewInt(2)

func PrivateKey(p *big.Int) *big.Int {
	private := new(big.Int).Sub(p, two)
	return private.Add(two, private.Rand(r, private))
}

func PublicKey(private, p *big.Int, g int64) *big.Int {
	return new(big.Int).Exp(big.NewInt(g), private, p)
}

func NewPair(p *big.Int, g int64) (private, public *big.Int) {
	private = PrivateKey(p)
	return private, PublicKey(private, p, g)
}

func SecretKey(private1, public2, p *big.Int) *big.Int {
	return new(big.Int).Exp(public2, private1, p)
}

Version data entries

177 entries across 177 versions & 1 rubygems

Version Path
trackler-2.2.1.56 tracks/go/exercises/diffie-hellman/example.go
trackler-2.2.1.55 tracks/go/exercises/diffie-hellman/example.go
trackler-2.2.1.54 tracks/go/exercises/diffie-hellman/example.go
trackler-2.2.1.53 tracks/go/exercises/diffie-hellman/example.go
trackler-2.2.1.52 tracks/go/exercises/diffie-hellman/example.go
trackler-2.2.1.51 tracks/go/exercises/diffie-hellman/example.go
trackler-2.2.1.50 tracks/go/exercises/diffie-hellman/example.go
trackler-2.2.1.49 tracks/go/exercises/diffie-hellman/example.go
trackler-2.2.1.48 tracks/go/exercises/diffie-hellman/example.go
trackler-2.2.1.47 tracks/go/exercises/diffie-hellman/example.go
trackler-2.2.1.46 tracks/go/exercises/diffie-hellman/example.go
trackler-2.2.1.45 tracks/go/exercises/diffie-hellman/example.go
trackler-2.2.1.44 tracks/go/exercises/diffie-hellman/example.go
trackler-2.2.1.43 tracks/go/exercises/diffie-hellman/example.go
trackler-2.2.1.42 tracks/go/exercises/diffie-hellman/example.go
trackler-2.2.1.41 tracks/go/exercises/diffie-hellman/example.go
trackler-2.2.1.40 tracks/go/exercises/diffie-hellman/example.go
trackler-2.2.1.39 tracks/go/exercises/diffie-hellman/example.go
trackler-2.2.1.38 tracks/go/exercises/diffie-hellman/example.go
trackler-2.2.1.37 tracks/go/exercises/diffie-hellman/example.go