From d8d18bdfd8b7dff26ea2af7d57b36f435710384b Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Fri, 4 Sep 2015 15:40:50 +0200 Subject: Add comments --- main.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 11a7356..2cf77af 100644 --- a/main.go +++ b/main.go @@ -1,3 +1,4 @@ +// Linear search factorization package main //go:generate openssl genrsa -out test.key 48 @@ -16,6 +17,7 @@ import ( ) func seed(N *big.Int) (<-chan *big.Int, <-chan *big.Int) { + // we start with sqrt(N) p := mathutil.SqrtBig(N) p.SetBit(p, 0, 1) // ensure it's odd @@ -26,6 +28,7 @@ func seed(N *big.Int) (<-chan *big.Int, <-chan *big.Int) { go func(c chan *big.Int, n *big.Int) { two := big.NewInt(2) for { + // search next prime n.Add(n, two) if n.ProbablyPrime(1) { c <- new(big.Int).Set(n) @@ -37,6 +40,7 @@ func seed(N *big.Int) (<-chan *big.Int, <-chan *big.Int) { go func(c chan *big.Int, n *big.Int) { two := big.NewInt(2) for { + // search previous prime n.Sub(n, two) if n.ProbablyPrime(1) { c <- new(big.Int).Set(n) @@ -55,11 +59,11 @@ func factor(N *big.Int) (*big.Int, *big.Int) { for { switch m.Mul(p, q).Cmp(N) { - case -1: + case -1: // m < N, go up p = <-nxt - case 0: + case 0: // found return p, q - case 1: + case 1: // m > N, go down q = <-prv } } -- cgit v1.2.3