summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-09-04 13:34:53 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-09-04 13:34:53 +0200
commit3c8364d1493f1a8a917a4e218d774268154df34e (patch)
tree240db760faeb77946c405f8bb46b48965803e4b3
parentf8ecfef6f4fe198876f8aebb17e3ddc1108901e3 (diff)
Add generate, simplify
-rw-r--r--main.go21
1 files changed, 9 insertions, 12 deletions
diff --git a/main.go b/main.go
index 678c386..c2a89aa 100644
--- a/main.go
+++ b/main.go
@@ -1,5 +1,7 @@
package main
+//go:generate openssl genrsa -out test.key 64
+
import (
"crypto/rsa"
"crypto/x509"
@@ -12,19 +14,13 @@ import (
"github.com/cznic/mathutil"
)
-var (
- one = big.NewInt(1)
- two = big.NewInt(2)
-)
-
-const confidence = 10
-
func next(N *big.Int) <-chan *big.Int {
- ch := make(chan *big.Int, 1)
+ ch := make(chan *big.Int)
go func(c chan *big.Int, n *big.Int) {
+ two := big.NewInt(2)
for {
n.Add(n, two)
- if n.ProbablyPrime(confidence) {
+ if n.ProbablyPrime(1) {
c <- new(big.Int).Set(n)
}
}
@@ -33,11 +29,12 @@ func next(N *big.Int) <-chan *big.Int {
}
func prev(N *big.Int) <-chan *big.Int {
- ch := make(chan *big.Int, 1)
+ ch := make(chan *big.Int)
go func(c chan *big.Int, n *big.Int) {
+ two := big.NewInt(2)
for {
n.Sub(n, two)
- if n.ProbablyPrime(confidence) {
+ if n.ProbablyPrime(1) {
c <- new(big.Int).Set(n)
}
}
@@ -78,7 +75,7 @@ func factor(N *big.Int) (*big.Int, *big.Int) {
func seed(N *big.Int) (*big.Int, *big.Int) {
p := mathutil.SqrtBig(N)
- p.SetBit(p, 0, 1)
+ p.SetBit(p, 0, 1) // ensure it's odd
q := new(big.Int).Set(p)
return p, q
}