summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-09-04 15:40:50 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-09-04 15:40:50 +0200
commitd8d18bdfd8b7dff26ea2af7d57b36f435710384b (patch)
treeccef91f6c143cd40aebfd2b1aebc50a15af7de5d
parent5d6d018b87f84e6493b6c605cdcb11d4ec89664b (diff)
Add comments
-rw-r--r--main.go10
1 files 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
}
}