add comments
This commit is contained in:
@@ -21,6 +21,9 @@ import (
|
||||
"math/big"
|
||||
)
|
||||
|
||||
/*
|
||||
Totient is a naive implementation of Euler's totient function.
|
||||
*/
|
||||
func Totient(n *big.Int) *big.Int {
|
||||
N := new(big.Int).Set(n)
|
||||
|
||||
@@ -52,6 +55,9 @@ func Totient(n *big.Int) *big.Int {
|
||||
return phi
|
||||
}
|
||||
|
||||
/*
|
||||
MultiplicativeOrder computes the smallest integer k such that g^k = 1 (mod modulus).
|
||||
*/
|
||||
func MultiplicativeOrder(g *big.Int, modulus *big.Int) *big.Int {
|
||||
e := new(big.Int).Set(g)
|
||||
var k *big.Int
|
||||
@@ -63,6 +69,9 @@ func MultiplicativeOrder(g *big.Int, modulus *big.Int) *big.Int {
|
||||
return k
|
||||
}
|
||||
|
||||
/*
|
||||
PrimitiveRoot computes a primitive root modulo modulus.
|
||||
*/
|
||||
func PrimitiveRoot(modulus *big.Int) (*big.Int, error) {
|
||||
if modulus.Cmp(big.NewInt(1)) == 0 {
|
||||
return big.NewInt(0), nil
|
||||
@@ -85,6 +94,9 @@ func PrimitiveRoot(modulus *big.Int) (*big.Int, error) {
|
||||
return nil, errors.New("no primitive root")
|
||||
}
|
||||
|
||||
/*
|
||||
PrimitiveRootFast computes a primitive root modulo modulus, utilizing the prime factorization of the totient of the modulus to find a solution more efficiently.
|
||||
*/
|
||||
func PrimitiveRootFast(modulus *big.Int, tpf map[string]*big.Int) (*big.Int, error) {
|
||||
phi := big.NewInt(1)
|
||||
for p, exp := range tpf {
|
||||
|
||||
Reference in New Issue
Block a user