Python 伦斯特拉';s椭圆曲线因式分解问题

Python 伦斯特拉';s椭圆曲线因式分解问题,python,elliptic-curve,prime-factoring,Python,Elliptic Curve,Prime Factoring,我尝试使用因子来计算小的(小于40位)复合整数 import math from fractions import gcd import random def lenstra_elliptic_curve_factor(N): """ Lenstra's elliptic curve factoring method """ if N <=0: raise Exception("Integer %s must be possitive " % N)

我尝试使用因子来计算小的(小于40位)复合整数

import math 
from fractions import gcd
import random 

def lenstra_elliptic_curve_factor(N):
     """ Lenstra's elliptic curve factoring method """

    if N <=0:
    raise Exception("Integer %s must be possitive " % N) 

    # Can't be 1 and can't factor a prime! 
    if 1 <= N <= 2 or is_probable_prime(N):
        return [N]

    # random point in the plain (values less than N)
    x0, y0 = random.randrange(1, N), random.randrange(1, N)

    factors = list()
    bound = int(math.sqrt(N))

    for a in xrange(2,N):
        # Build curve out of random points
        b = y0**2 - x0**3 - a*x0

        # Check curve is not singular 
        if 4*a**3 - 27*b**2 ==0:
            continue

        # Initially double point 
        s = 3*x0**2 + a
        (x,y) = (s**2 - 2*x0, s*((s**2 - 2*x0) - x0) - y0)

    # Keep adding points until gcd(x-x0,N) != 1
    for k in xrange(2,bound):
        for i in xrange(0,math.factorial(k)):
            d = gcd(x- x0,N)
            if d != 1:
                return lenstra_elliptic_curve_factor(int(d)) + lenstra_elliptic_curve_factor(int(N/d))
            else:
                # Point doubling arithmetic 
                s = (y - y0) * modInv(x - x0,N)
                x = s**2 - x - x0  
                y = - y + s * (s**2 - x - x0 - x)
我明白了

0 [0]
1 [1]
2 [2]
3 [3]
4 None
5 [5]
6 None
7 [7]
8 None
9 [3, 3]
10 [2, 5]
11 [11]
12

Traceback (most recent call last):
File "/AVcrypto/util.py", line 160, in <module>
     print x, lenstra_elliptic_curve_factor(x) 
File "/Users/Kevin/gd/proj/curr/honproj/AVcrypto/util.py", line 104, in lenstra_elliptic_curve_factor
     return lenstra_elliptic_curve_factor(int(d)) + lenstra_elliptic_curve_factor(int(N/d))
TypeError: can only concatenate list (not "NoneType") to list
0[0]
1 [1]
2 [2]
3 [3]
4无
5 [5]
6无
7 [7]
8无
9 [3, 3]
10 [2, 5]
11 [11]
12
回溯(最近一次呼叫最后一次):
文件“/AVcrypto/util.py”,第160行,在
打印x,伦斯特拉椭圆曲线系数(x)
文件“/Users/Kevin/gd/proj/curr/honproj/AVcrypto/util.py”,第104行,在lenstra椭圆曲线系数中
返回lenstra_椭圆曲线_因子(int(d))+lenstra_椭圆曲线_因子(int(N/d))
类型错误:只能将列表(而不是“非类型”)连接到列表

我曾尝试将测试的曲线数增加到
N**10
,但结果似乎相同。我只是想知道是否有人对这种算法有经验,特别是在某些数字似乎在相当长的时间内避免了试验过程的情况下

Lenstra的算法假设被分解的数字是6的共素数(也就是说,没有2或3的因子)。尝试使用因子4是行不通的。更现实的测试是系数13290059


我想你知道,对于40位数字来说,ECM是一个巨大的杀伤力。

我就这么说。在math.stackexchange.com(甚至是compsci),你可能会有更好的运气。谢谢,我也会尝试一下compsci!
0 [0]
1 [1]
2 [2]
3 [3]
4 None
5 [5]
6 None
7 [7]
8 None
9 [3, 3]
10 [2, 5]
11 [11]
12

Traceback (most recent call last):
File "/AVcrypto/util.py", line 160, in <module>
     print x, lenstra_elliptic_curve_factor(x) 
File "/Users/Kevin/gd/proj/curr/honproj/AVcrypto/util.py", line 104, in lenstra_elliptic_curve_factor
     return lenstra_elliptic_curve_factor(int(d)) + lenstra_elliptic_curve_factor(int(N/d))
TypeError: can only concatenate list (not "NoneType") to list