have lib function take map instead of list

This commit is contained in:
filifa
2025-08-21 19:52:05 -04:00
parent 0fdb60275f
commit 8333be5d2d
2 changed files with 25 additions and 10 deletions

View File

@@ -141,17 +141,16 @@ func PrimitiveRoot(modulus *big.Int) (*big.Int, error) {
return nil, errors.New("no primitive root")
}
func PrimitiveRootFast(modulus *big.Int, tpf []string) (*big.Int, error) {
func PrimitiveRootFast(modulus *big.Int, tpf map[string]*big.Int) (*big.Int, error) {
phi := big.NewInt(1)
factors := make(map[string]bool)
for _, s := range tpf {
p, ok := new(big.Int).SetString(s, 10)
for p, exp := range tpf {
pow, ok := new(big.Int).SetString(p, 10)
if !ok {
return nil, errors.New("invalid input " + s)
return nil, errors.New("invalid factor " + p)
}
phi.Mul(phi, p)
factors[p.Text(10)] = true
pow.Exp(pow, exp, nil)
phi.Mul(phi, pow)
}
for g := big.NewInt(1); g.Cmp(modulus) == -1; g.Add(g, big.NewInt(1)) {
@@ -161,7 +160,7 @@ func PrimitiveRootFast(modulus *big.Int, tpf []string) (*big.Int, error) {
}
isPrimitive := true
for p := range factors {
for p := range tpf {
e := new(big.Int)
f, _ := new(big.Int).SetString(p, 10)
k := new(big.Int).Div(phi, f)