iterate from 1 to m
This commit is contained in:
parent
dc952746a9
commit
c9cb78428f
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue