From c9cb78428f2e8b01bed27a095154c1a5d69fe0ba Mon Sep 17 00:00:00 2001 From: filifa Date: Wed, 10 Sep 2025 18:54:01 -0400 Subject: [PATCH] iterate from 1 to m --- cmd/discreteLog.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/discreteLog.go b/cmd/discreteLog.go index b3cbab1..44b3fb7 100644 --- a/cmd/discreteLog.go +++ b/cmd/discreteLog.go @@ -23,6 +23,7 @@ import ( "github.com/spf13/cobra" ) +// FIXME: order and generator may not be the right names here var discreteLogOrder string var discreteLogGenerator string var discreteLogElement string @@ -38,11 +39,12 @@ func ceilSqrt(x *big.Int) *big.Int { return z } +// FIXME: n is supposed to be the order, but i'm using it as the modulus func babyStepGiantStep(n, g, x *big.Int) *big.Int { m := ceilSqrt(n) table := make(map[string]*big.Int) - for j := big.NewInt(0); j.Cmp(m) == -1; j.Add(j, big.NewInt(1)) { + for j := big.NewInt(1); j.Cmp(m) <= 0; j.Add(j, big.NewInt(1)) { a := new(big.Int).Exp(g, j, n) table[a.String()] = new(big.Int).Set(j) } @@ -65,6 +67,7 @@ func babyStepGiantStep(n, g, x *big.Int) *big.Int { gamma.Mod(gamma, n) } + // TODO: return an error instead return nil }