add check for invertibility

This commit is contained in:
filifa 2025-09-10 21:23:26 -04:00
parent 78f8efa06a
commit fffdf712e7
1 changed files with 5 additions and 0 deletions

View File

@ -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))