func TestPollardRhoFactorizationBounded(t *testing.T) {
	B := smallPrimes[len(smallPrimes)-1]
	n := getSmoothNumber(B, 30, 10)
	factorization, err := pollardRhoFactorization(n, big.NewInt(int64(B)))
	if err != nil {
		t.Fatalf("error in bounded pollard rho factorization: %v", err)
	}
	checkFactorization(factorization, n, t)
}
Run Pollard rho factorization on a smooth number.
package dlog
import (
	"math/big"
	"math/rand"
	"testing"
	"time"
	"github.com/fentec-project/gofe/internal/keygen"
	"github.com/fentec-project/gofe/sample"
	"github.com/stretchr/testify/assert"
)
func TestPollardRho(t *testing.T) {
	params, err := getParams()
	if err != nil {
		t.Fatalf("Error during parameters generation: %v", err)
	}
	sampler := sample.NewUniformRange(big.NewInt(2), params.order)
	xCheck, err := sampler.Sample()
	if err != nil {
		t.Fatalf("Error during random int generation: %v", err)
	}
	h := new(big.Int).Exp(params.g, xCheck, params.p)
	x, err := pollardRho(h, params.g, params.p, params.order)
	if err != nil {
		t.Fatalf("Error in Pollard rho algorithm: %v", err)
	}
	assert.Equal(t, xCheck.Cmp(x), 0, "pollardRho result is wrong")
}
func TestPollardRhoParallel(t *testing.T) {
	params, err := getParams()
	if err != nil {
		t.Fatalf("Error during parameters generation: %v", err)
	}
	sampler := sample.NewUniformRange(big.NewInt(2), params.order)
	xCheck, err := sampler.Sample()
	if err != nil {
		t.Fatalf("Error during random int generation: %v", err)
	}
	h := new(big.Int).Exp(params.g, xCheck, params.p)
	x, err := pollardRhoParallel(h, params.g, params.p, params.order)
	if err != nil {
		t.Fatalf("Error in Pollard rho algorithm: %v", err)
	}
	assert.Equal(t, xCheck.Cmp(x), 0, "pollardRho result is wrong")
}
func TestPollardRhoFactorization(t *testing.T) {
	sampler := sample.NewUniform(new(big.Int).Exp(big.NewInt(2), big.NewInt(32), nil))
	n, err := sampler.Sample()
	if err != nil {
		t.Fatalf("Error during random int generation: %v", err)
	}
	factorization, err := pollardRhoFactorization(n, nil)
	if err != nil {
		t.Fatalf("error in pollard rho factorization: %v", err)
	}
	checkFactorization(factorization, n, t)
}
func TestPollardRhoElGamal(t *testing.T) {
	modulusLength := 32
	key, err := keygen.NewElGamal(modulusLength)
	if err != nil {
		t.Fatalf("Error in group generation: %v", err)
	}
	order := key.Q
	sampler := sample.NewUniform(new(big.Int).Exp(big.NewInt(2), big.NewInt(30), nil))
	xCheck, err := sampler.Sample()
	if err != nil {
		t.Fatalf("Error during random int generation: %v", err)
	}
	h := new(big.Int).Exp(key.G, xCheck, key.P)
	x, err := pollardRho(h, key.G, key.P, order)
	if err != nil {
		t.Fatalf("Error in Pollard rho algorithm: %v", err)
	}
	assert.Equal(t, xCheck.Cmp(x), 0, "pollardRho result is wrong")
}
func checkFactorization(factorization map[string]int, n *big.Int, t *testing.T) {
	nCheck := big.NewInt(1)
	for prime, power := range factorization {
		prime := new(big.Int).SetBytes([]byte(prime))
		if !prime.ProbablyPrime(10) {
			t.Errorf("%d is not prime, but should be", prime)
		}
		nCheck.Mul(nCheck, new(big.Int).Exp(prime, big.NewInt(int64(power)), big.NewInt(0)))
	}
	assert.Equal(t, nCheck.Cmp(n), 0, "Product of factor powers should match original number")
}
func TestPollardRhoFactorizationHard(t *testing.T) {
	p := keygen.GetGermainPrime(35)
	q := keygen.GetGermainPrime(35)
	n := new(big.Int).Mul(p, q)
	factorization, err := pollardRhoFactorization(n, nil)
	if err != nil {
		t.Fatalf("error in pollard rho factorization: %v", err)
	}
	checkFactorization(factorization, n, t)
}