From fffdf712e74d90f2b96ca723f8595463d0249288 Mon Sep 17 00:00:00 2001 From: filifa Date: Wed, 10 Sep 2025 21:23:26 -0400 Subject: [PATCH] add check for invertibility --- cmd/discreteLog.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmd/discreteLog.go b/cmd/discreteLog.go index a3259ef..f47c8e6 100644 --- a/cmd/discreteLog.go +++ b/cmd/discreteLog.go @@ -41,6 +41,11 @@ func ceilSqrt(x *big.Int) *big.Int { } func babyStepGiantStep(n, g, x, order *big.Int) (*big.Int, error) { + z := new(big.Int).GCD(nil, nil, g, n) + if z.Cmp(big.NewInt(1)) != 0 { + return nil, fmt.Errorf("base %v is not invertible modulo %v", g, n) + } + var m *big.Int if order == nil { // m = ceil(sqrt(n - 1))