add comments

This commit is contained in:
filifa
2025-09-30 23:58:28 -04:00
parent 5c42040e34
commit a760093f9d
12 changed files with 62 additions and 3 deletions

View File

@@ -33,9 +33,13 @@ func ceilSqrt(x *big.Int) *big.Int {
return z
}
// TODO: this can be extended to work with n, b not coprime
// https://cp-algorithms.com/algebra/discrete-log.html
/*
BabyStepGiantStep computes i such that b^i = x (mod n). For more efficient computation, provide the order of the group (i.e. totient(n)).
*/
func BabyStepGiantStep(n, b, x, order *big.Int) (*big.Int, error) {
// TODO: this function be extended to work with n, b not coprime
// https://cp-algorithms.com/algebra/discrete-log.html
z := new(big.Int).GCD(nil, nil, b, n)
if z.Cmp(big.NewInt(1)) != 0 {
return nil, fmt.Errorf("base %v and modulus %v are not coprime", b, n)