Skip to content

Commit 6c580bf

Browse files
committed
modified: Math/elliptic-curve_factorization_method_with_B2_stage.sf -- auto-select B1 and B2
1 parent 5d4e5c8 commit 6c580bf

File tree

1 file changed

+47
-14
lines changed

1 file changed

+47
-14
lines changed

Math/elliptic-curve_factorization_method_with_B2_stage.sf

+47-14
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Point(x_cord, z_cord, a_24, mod) {
4343
}
4444
}
4545

46-
func ecm_one_factor(n, B1=10000, B2=100000, max_curves=200, seed = nil) {
46+
func ecm_one_factor(n, B1=10000, B2=B1*100, max_curves=200, seed = nil) {
4747

4848
if (B1.is_odd || B2.is_odd) {
4949
die "The bounds must be both even integers"
@@ -55,11 +55,11 @@ func ecm_one_factor(n, B1=10000, B2=100000, max_curves=200, seed = nil) {
5555

5656
n.is_prime && return n
5757

58-
var D = B2.isqrt
59-
var beta = [0]*(D + 1)
60-
var S = [0]*(D + 1)
58+
var D = min(B2.isqrt, (B1>>1)-1)
59+
var beta = []
60+
var S = []
6161

62-
var k = primes(1, B1).prod {|p|
62+
var k = B1.primes.prod {|p|
6363
p**B1.ilog(p)
6464
}
6565

@@ -105,7 +105,7 @@ func ecm_one_factor(n, B1=10000, B2=100000, max_curves=200, seed = nil) {
105105
beta[1] = mulmod(S[1].x_cord, S[1].z_cord, n)
106106

107107
for d in (2 ..^ D) {
108-
S[d] = S[d-1].add(Q2, S[d-2])
108+
S[d] = S[d-1].add(Q2, S[d-2])
109109
beta[d] = mulmod(S[d].x_cord, S[d].z_cord, n)
110110
}
111111

@@ -141,10 +141,39 @@ func ecm_one_factor(n, B1=10000, B2=100000, max_curves=200, seed = nil) {
141141
die "Increase the bounds"
142142
}
143143

144-
func ecm(n, B1=10000, B2=100000, max_curves=200, seed = nil) {
144+
# Parameters from:
145+
# https://www.rieselprime.de/ziki/Elliptic_curve_method
146+
147+
var ECM_PARAMS = [
148+
149+
# d B1 curves
150+
[10, 360, 7]
151+
[15, 2000, 25]
152+
[20, 11000, 90]
153+
[25, 50000, 300]
154+
[30, 250000, 700]
155+
[35, 1000000, 1800]
156+
[40, 3000000, 5100]
157+
[45, 11000000, 10600]
158+
[50, 43000000, 19300]
159+
[55, 110000000, 49000]
160+
[60, 260000000, 124000]
161+
[65, 850000000, 210000]
162+
[70, 2900000000, 340000]
163+
]
164+
165+
func ecm(n, B1=nil, B2=nil, max_curves=nil, seed = nil) {
145166

146167
n <= 1 && die "n must be greater than 1"
147168

169+
if (!defined(B1)) {
170+
for d, B1, curves in ECM_PARAMS {
171+
say ":: Trying to find a prime factor with #{d} digits using B1 = #{B1} with #{curves} curves"
172+
var f = try { __FUNC__(n, B1, B1*50, curves, seed) }
173+
return f if defined(f)
174+
}
175+
}
176+
148177
var f = n.trial_factor(100_000)
149178
n = f.pop
150179
var factors = Set(f...)
@@ -172,11 +201,15 @@ func ecm(n, B1=10000, B2=100000, max_curves=200, seed = nil) {
172201
return final_factors.sort
173202
}
174203

175-
say ecm(314159265358979323, 100, 1000) #=> [317213509, 990371647]
176-
say ecm(14304849576137459, 100, 1000) #=> [16100431, 888476189]
177-
say ecm(9804659461513846513, 100, 1000) #=> [4641991, 2112166839943]
178-
say ecm(25645121643901801, 100, 1000) #=> [5394769, 4753701529]
204+
const SEED = 42
205+
206+
say ecm(314159265358979323, seed:SEED) #=> [317213509, 990371647]
207+
say ecm(14304849576137459, seed:SEED) #=> [16100431, 888476189]
208+
say ecm(9804659461513846513, seed:SEED) #=> [4641991, 2112166839943]
209+
say ecm(25645121643901801, seed:SEED) #=> [5394769, 4753701529]
210+
say ecm(17177619065692036843, seed:SEED) #=> [2957613037, 5807933239]
211+
say ecm(195905123644566489241411490581, seed:SEED) #=> [259719190596553, 754295911652077]
179212

180-
say ecm(2**64 + 1, 100, 1000) #=> [274177, 67280421310721]
181-
say ecm(2**128 - 1, 100, 1000) #=> [3, 5, 17, 257, 641, 65537, 274177, 6700417, 67280421310721]
182-
#say ecm(2**128 + 1, 10000) # takes ~17 seconds
213+
say ecm(2**64 + 1, seed:SEED) #=> [274177, 67280421310721]
214+
say ecm(2**128 - 1, seed:SEED) #=> [3, 5, 17, 257, 641, 65537, 274177, 6700417, 67280421310721]
215+
#say ecm(2**128 + 1, seed:SEED) # takes ~26 seconds

0 commit comments

Comments
 (0)