示例#1
0
def root_method(n):
    a = intsqrt(n) + 1
    test = intsqrt(a**2 - n)
    while not (test**2 == (a**2 - n)):
        a = a + 1
        test = intsqrt(a**2 - n)
    return (a, test)
def root_method(n):
    a = intsqrt(n) + 1
    test = intsqrt(a**2 - n)
    while not (test**2 == (a**2 - n)):
        a = a + 1
        test = intsqrt(a**2 - n)
    return (a, test)
示例#3
0
def root_method(N):
    a = intsqrt(N)
    b2 = 1
    b = 0
    while (b*b != b2):
        a += 1
        b2 = a*a-N
        b = intsqrt(b2)
    return a-b
def root_method(N):
    a = intsqrt(N)
    if a*a < N:
        a = a + 1

    while True:
        b=intsqrt(a*a - N)
        if b*b == a*a - N:
            return a-b
        a=a+1
示例#5
0
def root_method(N):
    a = intsqrt(N)
    while a*a - N < 0:
      a += 1

    while (a*a-N) != intsqrt(a*a-N)*intsqrt(a*a-N):
      a += 1
          
    b = intsqrt(a*a-N)
    return a-b
示例#6
0
def root_method(N):
    a = intsqrt(N)
    if a * a < N:
        a = a + 1

    while True:
        b = intsqrt(a * a - N)
        if b * b == a * a - N:
            return a - b
        a = a + 1
示例#7
0
def root_method(N):
    a = intsqrt(N) + 1

    for i in range(a, N + 1):

        b = intsqrt(i**2 - N)

        if b % 1 == 0:
            print(b)
            return i - b
示例#8
0
def root_method(N):
    """
  1. initialize integer a to be an integer greater than root(N)
  2. check if root(a^2 - N) is an integer
  3. is so, let b = root(a^2 - N). return a - b.
  4. If not, repeat with the next greater value of a.
  """
    a = math.floor(factoring_support.intsqrt(N)) + 1
    while True:
        b = factoring_support.intsqrt(a**2 - N)
        if is_integer(b):
            return a - b
        a += 1
def find_candidates(N, primeset):
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes

    Output:
        - a list [roots, rowlist]
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    '''
    roots = []
    rowlist = []
    size = len(primeset) + 1
    t=2
    count=0

    while count < size:
        a=intsqrt(N)+t
        factors = dumb_factor(a*a-N, primeset)
        if len(factors) > 0:
            roots.append(a)
            rowlist.append(make_Vec(primeset,factors))
            count = count + 1
        t=t+1
    return (roots, rowlist)
示例#10
0
def find_a_and_b(v, roots, N):
    '''
    Input: 
     - a {0,1,..., n-1}-vector v over GF(2) where n = len(roots)
     - a list roots of integers
     - an integer N to factor
    Output:
      a pair (a,b) of integers
      such that a*a-b*b is a multiple of N
      (if v is correctly chosen)
    '''
    alist = []
    d=[]
    
    for k, v in v.f.items():
        if v == one:
            d.append(k)
    for n, root in enumerate(roots):
        if n in d:
            alist.append(root)      
    a = prod(alist)
    c = prod(x*x -N for x in alist)
    b = intsqrt(c)
    if b*b == c:
        return a, b
示例#11
0
def find_candidates(N, primeset):
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes

    Output:
        - a list [roots, rowlist]
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    '''
    s = intsqrt(N)+2
    roots = []
    rowlist = []
    while True:
        if len(roots) > len(primeset):
            break
        result = dumb_factor(s*s-N, primeset)
        if len(result)> 0:
            roots.append(s)
            rowlist.append(make_Vec(primeset, result))
        s = s+1
    return (roots, rowlist)
示例#12
0
def find_candidates(N, primeset):
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes

    Output:
        - a list [roots, rowlist]
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    '''
    roots = []
    rowlists = []

    target_count = len(primeset) + 1
    x = intsqrt(N) + 2
    while (len(roots) < target_count):
        factors = dumb_factor(x * x - N, primeset)
        if len(factors) > 0:
            v = make_Vec(primeset, factors)
            roots.append(x)
            rowlists.append(v)
        x = x + 1
    return (roots, rowlists)
示例#13
0
def find_candidates(N, primeset):
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes

    Output:
        - a list [roots, rowlist]
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    '''
    roots=[]
    rowlist = []
    i = 2
    k=0
    while k < len(primeset)+1:
        x = intsqrt(N)+i
        T = dumb_factor(x*x - N, primeset)
        if T != []:
            roots.append(x)
            factors = T
            row = make_Vec(primeset, factors)
            rowlist.append(row)
            k +=1
        i +=1
        
    return roots, rowlist
示例#14
0
def find_a_and_b(v, roots, N):
    '''
    Input: 
     - a {0,1,..., n-1}-vector v over GF(2) where n = len(roots)
     - a list roots of integers
     - an integer N to factor
    Output:
      a pair (a,b) of integers
      such that a*a-b*b is a multiple of N
      (if v is correctly chosen)
    '''
    alist = []
    d = []

    for k, v in v.f.items():
        if v == one:
            d.append(k)
    for n, root in enumerate(roots):
        if n in d:
            alist.append(root)
    a = prod(alist)
    c = prod(x * x - N for x in alist)
    b = intsqrt(c)
    if b * b == c:
        return a, b
示例#15
0
def find_candidates(N, primeset):
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes

    Output:
        - a list [roots, rowlist]
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    '''
    roots = list()
    rowlist = list()
    count = 0
    i = 2
    while count < len(primeset) + 1:
        x = intsqrt(N) + i
        df = dumb_factor(x*x -N,primeset)
        if len(df) != 0:
            roots.append(x)
            rowlist.append(make_Vec(primeset,df)) 
            count +=1
        i += 1
    return (roots,rowlist)
               
    pass
def find_candidates(N, primeset):
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes

    Output:
        - a list [roots, rowlist]
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    '''
    x = intsqrt(N) + 2
    roots = []
    rowlist = []
    while len(roots) <= len(primeset):
        y = x*x - N
        tmprow = dumb_factor(y, primeset)
        if tmprow != []:
            roots.append(x)
            rowlist.append(make_Vec(primeset, tmprow))
        x += 1
    return (roots, rowlist)
示例#17
0
def find_candidates(N, primeset):
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes

    Output:
        - a list [roots, rowlist]
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    '''
    roots = []
    rowlist = []
    i = 2
    k = 0
    while k < len(primeset) + 1:
        x = intsqrt(N) + i
        T = dumb_factor(x * x - N, primeset)
        if T != []:
            roots.append(x)
            factors = T
            row = make_Vec(primeset, factors)
            rowlist.append(row)
            k += 1
        i += 1

    return roots, rowlist
示例#18
0
def find_candidates(N, primeset):
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes

    Output:
        - a list [roots, rowlist]
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    '''
    roots = []
    rowlist = []
    x = intsqrt(N) + 1

    while True:
        x += 1
        factors = dumb_factor(x*x - N, primeset) 
        
        if factors != []:
            roots.append(x)
            rowlist.append(make_Vec(primeset, factors))

        if len(roots) > len(primeset):
            return (roots, rowlist)
def find_candidates(N, primeset):
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes

    Output:
        - a list [roots, rowlist]
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    '''
    roots = []
    rowlist = []
    increment = 2

    while len(roots) < len(primeset) + 1:
        x = intsqrt(N) + increment
        increment += 1
        xx_minus_n = x ** 2 - N
        factors = dumb_factor(xx_minus_n, primeset)
        if factors:
            roots.append(x)
            rowlist.append(make_Vec(primeset, factors))

    return (roots, rowlist)
示例#20
0
def find_candidates(N, primeset):
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes

    Output:
        - a list [roots, rowlist]
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    '''
    a_list = []
    a_factor_vecs = []
    a = intsqrt(N) + 2
    while (len(a_list) <= len(primeset)):
        prime_factors = dumb_factor(a**2 - N, primeset)
        if (len(prime_factors) > 0):
            a_list.append(a)
            ##print(len(a_list), a)
            a_factor_vecs.append(make_Vec(primeset, prime_factors))
        a = a + 1
    return (a_list, a_factor_vecs)
示例#21
0
def root_method(N):
    '''(int) -> int
    Return first integer that is equal to sqrt(a*a - N), where a is
    another integer greater than sqrt(N).
    >>> root_method(77)
    2
    '''
    a = intsqrt(N)
    if a*a < N:
        a += 1
    while True:
        diff = a*a - N
        b = intsqrt(diff)
        if b*b == diff:
            return a-b
        a += 1
示例#22
0
def root_method(N):
    '''(int) -> int
    Return first integer that is equal to sqrt(a*a - N), where a is
    another integer greater than sqrt(N).
    >>> root_method(77)
    2
    '''
    a = intsqrt(N)
    if a * a < N:
        a += 1
    while True:
        diff = a * a - N
        b = intsqrt(diff)
        if b * b == diff:
            return a - b
        a += 1
示例#23
0
def find_candidates(N, primeset):
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes

    Output:
        - a list [roots, rowlist]
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    '''
    roots = []
    rowlist = []
    i = 2
    base = intsqrt(N)
    while len(roots) < len(primeset)+1:
        x = base + i
        testFac = dumb_factor(x*x-N, primeset)
        if len(testFac) > 0:
            roots.append(x)
            rowlist.append(make_Vec(primeset, testFac))
        i += 1
    return (roots, rowlist)
示例#24
0
def find_candidates(N, primeset):
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes

    Output:
        - a list [roots, rowlist]
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    '''
    roots = []
    rowlist = []
    base = intsqrt(N) + 1
    while (len(roots) <= len(primeset)):  ## len(roots) == len(primeset) + 1
        base += 1
        df = dumb_factor(base**2 - N, primeset)
        if df == []:
            continue
        roots.append(base)
        rowlist.append(make_Vec(primeset, df))
    return (roots, rowlist)
def find_candidates(N, primeset):
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes

    Output:
        - a list [roots, rowlist]
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    '''
    roots = []
    rowlist = []
    count = 0
    x = intsqrt(N) + 1
    while count < len(primeset) + 1:
        
        # start with value = (previous+1)
        x = x + 1
        while True:
            factors = dumb_factor(x*x - N, primeset)
            # if can be factored
            if len(factors) != 0:
                factors_GF2 = make_Vec(primeset, factors)
                roots.append(x)
                rowlist.append(factors_GF2)
                break
            # if not
            else:
                x = x + 1
        count = count + 1
    return roots,rowlist      
示例#26
0
def find_a_and_b(v, roots, N):
    alist = [roots[i] for i in v.D if v[i] == one]
    a = prod(alist)
    c = prod([x * x - N for x in alist])
    b = intsqrt(c)
    assert b * b == c
    return (a, b)
示例#27
0
def find_candidates(N, primeset):
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes

    Output:
        - a list [roots, rowlist]
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    '''
    a_list = []
    a_factor_vecs = []
    a = intsqrt(N) + 2
    while (len(a_list) <= len(primeset)):
        prime_factors = dumb_factor(a**2 - N, primeset)
        if (len(prime_factors) > 0):
            a_list.append(a)
            ##print(len(a_list), a)
            a_factor_vecs.append(make_Vec(primeset, prime_factors))
        a = a + 1
    return (a_list, a_factor_vecs)
示例#28
0
def find_candidates(N, primeset):
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes

    Output:
        - a list [roots, rowlist]
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    '''
    roots = []
    rowlist = []
    base = intsqrt(N) + 1
    while(len(roots) <= len(primeset)):  ## len(roots) == len(primeset) + 1
        base += 1
        df = dumb_factor(base**2 - N,primeset)
        if df == []:
            continue
        roots.append(base)
        rowlist.append(make_Vec(primeset,df))
    return (roots,rowlist)
示例#29
0
def find_candidates(N, primeset):
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes

    Output:
        - a tuple(roots, rowlist)
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    '''
    roots = list()
    rowlist = list()
    i = 2
    while len(roots) < len(primeset) + 1:
        x = intsqrt(N) + i
        factors = dumb_factor(x**2 - N, primeset)
        vec = make_Vec(primeset,factors)
        if len(factors) > 0 and len(vec.f) > 0:
            roots.append(x)
            rowlist.append(vec)
        i += 1
    return (roots,rowlist)
示例#30
0
def find_a_and_b(v, roots, N):
    '''
    Input: 
     - a {0,1,..., n-1}-vector v over GF(2) where n = len(roots)
     - a list roots of integers
     - an integer N to factor
    Output:
      a pair (a,b) of integers
      such that a*a-b*b is a multiple of N
      (if v is correctly chosen)
    Example:
        >>> roots = [51, 52, 53, 58, 61, 62, 63, 67, 68, 71, 77, 79]
        >>> N = 2419
        >>> v = Vec({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},{1: one, 2: one, 11: one, 5: one})  
        >>> find_a_and_b(v, roots, N)
        (13498888, 778050)
        >>> v = Vec({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},{0: 0, 1: 0, 10: one, 2: one})
        >>> find_a_and_b(v, roots, N)
        (4081, 1170)
    '''
    chosen_xes = []
    for label in v.D:
        if v[label] != 0:
            chosen_xes.append(roots[label])

    a = 1
    b = 1
    for x in chosen_xes:
        a *= x
        b *= x**2 - N
    b = intsqrt(b)
    return a, b
示例#31
0
def find_candidates(N, primeset):
    '''
Input:
- N: an int to factor
- primeset: a set of primes

Output:
- a list [roots, rowlist]
- roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
over primeset
- rowlist: a list such that rowlist[i] is a
primeset-vector over GF(2) corresponding to a_i
such that len(roots) = len(rowlist) and len(roots) > len(primeset)
'''
    roots = []
    rowlist = []
    x = intsqrt(N)+2

    while len(roots) <= len(primeset):
      xSquareMinN = x*x - N
      factorPair = dumb_factor(xSquareMinN , primeset)
      if len(factorPair) > 0:
        vecF = make_Vec(primeset, factorPair)
        roots.append(x)
        rowlist.append(vecF)
      x += 1

    return (roots, rowlist)
示例#32
0
def find_candidates(N, primeset):
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes

    Output:
        - a list [roots, rowlist]
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    '''
    roots = list()
    rowlist = list()

    x = intsqrt(N) + 2

    while (len(roots) < (len(primeset) + 1)):

        dumb_factored = dumb_factor(x**2 - N, primeset)
        if len(dumb_factored) != 0:
            roots = roots + [x]
            rowlist = rowlist + [make_Vec(primeset, dumb_factored)]

        x += 1
    return roots, rowlist
示例#33
0
def find_candidates(N, primeset):
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes

    Output:
        - a list [roots, rowlist]
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    '''
    roots = []
    rowlist = []
    size = len(primeset) + 1
    t = 2
    count = 0

    while count < size:
        a = intsqrt(N) + t
        factors = dumb_factor(a * a - N, primeset)
        if len(factors) > 0:
            roots.append(a)
            rowlist.append(make_Vec(primeset, factors))
            count = count + 1
        t = t + 1
    return (roots, rowlist)
示例#34
0
def find_candidates(N, primeset):
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes

    Output:
        - a list [roots, rowlist]
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    '''
    roots = []
    rowlist = []
    x = intsqrt(N) + 1

    while True:
        x += 1
        factors = dumb_factor(x * x - N, primeset)

        if factors != []:
            roots.append(x)
            rowlist.append(make_Vec(primeset, factors))

        if len(roots) > len(primeset):
            return (roots, rowlist)
示例#35
0
def find_a_and_b(v, roots, N):
    '''
    Input:
     - a {0,1,..., n-1}-vector v over GF(2) where n = len(roots)
     - a list roots of integers
     - an integer N to factor
    Output:
      a pair (a,b) of integers
      such that a*a-b*b is a multiple of N
      (if v is correctly chosen)
    Example:
        >>> roots = [51, 52, 53, 58, 61, 62, 63, 67, 68, 71, 77, 79]
        >>> N = 2419
        >>> v = Vec({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},{1: one, 2: one, 11: one, 5: one})
        >>> find_a_and_b(v, roots, N)
        (13498888, 778050)
        >>> v = Vec({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},{0: 0, 1: 0, 10: one, 2: one})
        >>> find_a_and_b(v, roots, N)
        (4081, 1170)
    '''
    alist = [roots[x] for x in range(len(roots)) if v[x]]
    a = prod(alist)
    c = prod([x**2 - N for x in alist])
    b = intsqrt(c)
    assert b * b == c
    return (a, b)
示例#36
0
def find_candidates(N, primeset):
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes

    Output:
        - a list [roots, rowlist]
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    '''
    roots = []
    rowlist = []
    i = 2
    base = intsqrt(N)
    while len(roots) < len(primeset) + 1:
        x = base + i
        testFac = dumb_factor(x * x - N, primeset)
        if len(testFac) > 0:
            roots.append(x)
            rowlist.append(make_Vec(primeset, testFac))
        i += 1
    return (roots, rowlist)
def find_a_and_b(v, roots, N):
    '''
    Input: 
     - a {0,1,..., n-1}-vector v over GF(2) where n = len(roots)
     - a list roots of integers
     - an integer N to factor
    Output:
      a pair (a,b) of integers
      such that a*a-b*b is a multiple of N
      (if v is correctly chosen)
    Example:
        >>> roots = [51, 52, 53, 58, 61, 62, 63, 67, 68, 71, 77, 79]
        >>> N = 2419
        >>> v = Vec({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},{1: one, 2: one, 11: one, 5: one})  
        >>> find_a_and_b(v, roots, N)
        (13498888, 778050)
        >>> v = Vec({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},{0: 0, 1: 0, 10: one, 2: one})
        >>> find_a_and_b(v, roots, N)
        (4081, 1170)
    '''
    chosen_xes = []
    for label in v.D:
        if v[label] != 0: 
            chosen_xes.append(roots[label])
        
    a = 1
    b = 1
    for x in chosen_xes:
        a *= x   
        b *= x**2-N
    b = intsqrt(b)
    return a,b
示例#38
0
def find_candidates(N, primeset):
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes

    Output:
        - a list [roots, rowlist]
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    '''
    roots = []
    rowlist = []
    total = len(primeset) + 1
    a = intsqrt(N) + 2
    while len(roots) < total:
        row = dumb_factor(a * a - N, primeset)
        if not row:
            a += 1
            continue
        roots.append(a)
        rowlist.append(make_Vec(primeset, row))
        a += 1

    return (roots, rowlist)
示例#39
0
def find_candidates(N, primeset):
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes

    Output:
        - a list [roots, rowlist]
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    '''
    roots = []
    rowlist = []
    total = len(primeset) + 1
    a = intsqrt(N) + 2
    while len(roots) < total:
        row = dumb_factor(a * a - N, primeset)
        if not row:
            a += 1
            continue
        roots.append(a)
        rowlist.append(make_Vec(primeset, row))
        a += 1

    return (roots, rowlist)
示例#40
0
def root_method(N):
    a = intsqrt(N)
    print(a)
    while True:
        a += 1
        b = sqrt(a * a - N)

        if b == int(b):
            return (a - b, a + int(b))
示例#41
0
def find_candidates(N, primeset):
    roots = []
    rowlist = []
    x = intsqrt(N) + 2
    while len(roots) < len(primeset) + 1:
        factors = dumb_factor(x * x - N, primeset)
        if len(factors) > 0:
            roots.append(x)
            rowlist.append(make_Vec(primeset, factors))
        x += 1
    return roots, rowlist
示例#42
0
def find_a_and_b(M,roots,N, row):
    v = M[row]
    alist = [roots[k] for (k,v) in v.f.items() if v == one]
    a = prod(alist)
    c = prod({a*a - N for a in alist})
    b = intsqrt(c)
    if b * b == c:
        return a,b
    else:
        row -= 1
        return find_a_and_b(M,roots,N,row)
示例#43
0
def root_method(N):
    from math import sqrt

    a_fail = True
    loop_max = 2 * N
    loop_count = 0
    b = -1

    if intsqrt(N) < sqrt(N): a = intsqrt(N) + 1
    else: a = intsqrt(N)

    while (a_fail and loop_count < loop_max):

        if intsqrt(a**2 - N) == sqrt(a**2 - N):
            b = intsqrt(a**2 - N)
            a_fail = False
        if a_fail: a += 1
        loop_count += 1
    if b == -1: a = "Error: Root Not Found"
    return a, b
示例#44
0
def find_candidates(N, primeset):
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes

    Output:
        - a tuple (roots, rowlist)
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    Example:
        >>> from factoring_support import primes
        >>> N = 2419
        >>> primeset = primes(32)
        >>> roots, rowlist = find_candidates(N, primeset)
        >>> set(roots) == set([51, 52, 53, 58, 61, 62, 63, 67, 68, 71, 77, 79])
        True
        >>> D = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31}
        >>> set(rowlist) == set([Vec(D,{2: one, 13: one, 7: one}),\
                Vec(D,{3: one, 19: one, 5: one}),\
                Vec(D,{2: one, 3: one, 5: one, 13: one}),\
                Vec(D,{3: one, 5: one, 7: one}),\
                Vec(D,{7: one, 2: one, 3: one, 31: one}),\
                Vec(D,{3: one, 19: one}),\
                Vec(D,{2: one, 31: one}),\
                Vec(D,{2: one, 5: one, 23: one}),\
                Vec(D,{5: one}),\
                Vec(D,{3: one, 2: one, 19: one, 23: one}),\
                Vec(D,{2: one, 3: one, 5: one, 13: one}),\
                Vec(D,{2: one, 3: one, 13: one})])
        True
    '''
    count = 0
    x = intsqrt(N) + 1
    prime_num = len(primeset)
    roots = []
    rowlist = []

    while count < prime_num + 1:
        x += 1

        dumb_factor_res = dumb_factor(x * x - N, primeset)
        if not dumb_factor_res:
            continue

        f = make_Vec(primeset, dumb_factor_res)
        roots.append(x)
        rowlist.append(f)
        count += 1
    return roots, rowlist
def find_candidates(N, primeset):
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes

    Output:
        - a tuple (roots, rowlist)
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    Example:
        >>> from factoring_support import primes
        >>> N = 2419
        >>> primeset = primes(32)
        >>> roots, rowlist = find_candidates(N, primeset)
        >>> set(roots) == set([51, 52, 53, 58, 61, 62, 63, 67, 68, 71, 77, 79])
        True
        >>> D = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31}
        >>> set(rowlist) == set([Vec(D,{2: one, 13: one, 7: one}),\
                Vec(D,{3: one, 19: one, 5: one}),\
                Vec(D,{2: one, 3: one, 5: one, 13: one}),\
                Vec(D,{3: one, 5: one, 7: one}),\
                Vec(D,{7: one, 2: one, 3: one, 31: one}),\
                Vec(D,{3: one, 19: one}),\
                Vec(D,{2: one, 31: one}),\
                Vec(D,{2: one, 5: one, 23: one}),\
                Vec(D,{5: one}),\
                Vec(D,{3: one, 2: one, 19: one, 23: one}),\
                Vec(D,{2: one, 3: one, 5: one, 13: one}),\
                Vec(D,{2: one, 3: one, 13: one})])
        True
    '''
    count = 0
    x = intsqrt(N) + 1
    prime_num = len(primeset)
    roots = []
    rowlist = []
    
    while count < prime_num + 1:
        x += 1
        
        dumb_factor_res = dumb_factor(x*x-N, primeset)
        if not dumb_factor_res:
            continue
        
        f = make_Vec(primeset, dumb_factor_res)
        roots.append(x)
        rowlist.append(f)
        count += 1
    return roots, rowlist    
def root_method(N):
    a = intsqrt(N)
    for i in range (a+1, N):
        d = i*i - N
        if d < 0: 
            continue
        else: 
            b = sqrt(d)
            #print(str(i) + ':' + str(b))
        if b%1 == 0: 
            return int(i-b)

    return None
示例#47
0
def find_a_and_b(v, roots, N):
    '''
    Input: 
     - a {0,1,..., n-1}-vector v over GF(2) where n = len(roots)
     - a list roots of integers
     - an integer N to factor
    Output:
      a pair (a,b) of integers
      such that a*a-b*b is a multiple of N
      (if v is correctly chosen)
    '''
    af = [roots[idx] for idx in v.D if v[idx] == one]
    bf = [x**2 - N for x in af]
    return (prod(af),intsqrt(prod(bf)))
示例#48
0
def find_candidates(N, primeset):
    roots = []
    rowlist = []
    x = intsqrt(N) + 1
    while (True):
        x += 1
        factors = dumb_factor(x * x - N, primeset)
        if len(factors) > 0:
            roots.append(x)
            rowlist.append(make_Vec(primeset, factors))
            if len(roots) >= len(primeset) + 1:
                break

    return (roots, rowlist)
示例#49
0
def find_a_and_b(v, roots, N):
    '''
    Input: 
     - a {0,1,..., n-1}-vector v over GF(2) where n = len(roots)
     - a list roots of integers
     - an integer N to factor
    Output:
      a pair (a,b) of integers
      such that a*a-b*b is a multiple of N
      (if v is correctly chosen)
    '''
    af = [roots[idx] for idx in v.D if v[idx] == one]
    bf = [x**2 - N for x in af]
    return (prod(af), intsqrt(prod(bf)))
示例#50
0
def find_candidates(N, primeset):
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes

    Output:
        - a tuple (roots, rowlist)
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    Example:
        >>> from factoring_support import primes
        >>> N = 2419
        >>> primeset = primes(32)
        >>> roots, rowlist = find_candidates(N, primeset)
        >>> set(roots) == set([51, 52, 53, 58, 61, 62, 63, 67, 68, 71, 77, 79])
        True
        >>> D = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31}
        >>> set(rowlist) == set([Vec(D,{2: one, 13: one, 7: one}),\
                Vec(D,{3: one, 19: one, 5: one}),\
                Vec(D,{2: one, 3: one, 5: one, 13: one}),\
                Vec(D,{3: one, 5: one, 7: one}),\
                Vec(D,{7: one, 2: one, 3: one, 31: one}),\
                Vec(D,{3: one, 19: one}),\
                Vec(D,{2: one, 31: one}),\
                Vec(D,{2: one, 5: one, 23: one}),\
                Vec(D,{5: one}),\
                Vec(D,{3: one, 2: one, 19: one, 23: one}),\
                Vec(D,{2: one, 3: one, 5: one, 13: one}),\
                Vec(D,{2: one, 3: one, 13: one})])
        True
    '''
    # initialization
    roots = []
    rowlist = []
    x = intsqrt(N) + 1
    goal = len(primeset) + 1
    while True:
        x += 1
        cdiff = x*x - N
        dumb_list = dumb_factor(cdiff, primeset)
        if len(dumb_list) > 0:
            roots.append(x)
            rowlist.append(make_Vec(primeset, dumb_list))
        if len(roots) == goal:
            break
    return(roots, rowlist)
def find_candidates(N, primeset):
    for x in primeset:
	intsqrt(2419) + x
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes,
        >>> primes(32)
           {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31}

    Output:
        - a list [roots, rowlist]
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    '''
    roots = []
    rowlist = []
    for x in primeset:
        intsqrt(2419) + x

    return [roots,rowlist]
示例#52
0
def find_candidates(N, primeset):
    '''
    Input:
        - N: an int to factor
        - primeset: a set of primes

    Output:
        - a tuple (roots, rowlist)
        - roots: a list a_0, a_1, ..., a_n where a_i*a_i - N can be factored
                 over primeset
        - rowlist: a list such that rowlist[i] is a
                   primeset-vector over GF(2) corresponding to a_i
          such that len(roots) = len(rowlist) and len(roots) > len(primeset)
    Example:
        >>> from factoring_support import primes
        >>> N = 2419
        >>> primeset = primes(32)
        >>> roots, rowlist = find_candidates(N, primeset)
        >>> set(roots) == set([51, 52, 53, 58, 61, 62, 63, 67, 68, 71, 77, 79])
        True
        >>> D = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31}
        >>> set(rowlist) == set([Vec(D,{2: one, 13: one, 7: one}),\
                Vec(D,{3: one, 19: one, 5: one}),\
                Vec(D,{2: one, 3: one, 5: one, 13: one}),\
                Vec(D,{3: one, 5: one, 7: one}),\
                Vec(D,{7: one, 2: one, 3: one, 31: one}),\
                Vec(D,{3: one, 19: one}),\
                Vec(D,{2: one, 31: one}),\
                Vec(D,{2: one, 5: one, 23: one}),\
                Vec(D,{5: one}),\
                Vec(D,{3: one, 2: one, 19: one, 23: one}),\
                Vec(D,{2: one, 3: one, 5: one, 13: one}),\
                Vec(D,{2: one, 3: one, 13: one})])
        True
    '''
    roots = []
    rowlist = []
    target = len(primeset) + 1
    x = intsqrt(N) + 1

    while (len(roots) < target and len(rowlist) < target):
        x = x + 1
        result = dumb_factor(x * x - N, primeset)
        if (result != []):
            roots.append(x)
            rowlist.append(make_Vec(primeset, result))

    return (roots, rowlist)
示例#53
0
def find_a_and_b(v, roots, N):
    '''
    Input: 
     - a {0,1,..., n-1}-vector v over GF(2) where n = len(roots)
     - a list roots of integers
     - an integer N to factor
    Output:
      a pair (a,b) of integers
      such that a*a-b*b is a multiple of N
      (if v is correctly chosen)
    '''
    alist = [ roots[i] for i in range(len(roots)) if v[i] != 0 ] 
    a = prod(alist)
    c = prod( { x*x - N for x in alist } )
    b = intsqrt(c)
    return (a, b)
示例#54
0
def find_a_and_b(v, roots, N):
    """
   a vector v
   the list roots
   the integer N to factor

   computes a pair of integers such that a**2 - b**2 is
   a multiple of N
  """
    alist = [roots[i] for i in v.D if v[i] != 0]
    a = factoring_support.prod(alist)
    c = factoring_support.prod([x * x - N for x in alist])
    assert (c > 0)
    b = factoring_support.intsqrt(c)
    assert (b * b == c)
    return (a, b)
示例#55
0
def find_a_and_b(v, roots, N):
    '''
    Input: 
     - a {0,1,..., n-1}-vector v over GF(2) where n = len(roots)
     - a list roots of integers
     - an integer N to factor
    Output:
      a pair (a,b) of integers
      such that a*a-b*b is a multiple of N
      (if v is correctly chosen)
    '''
    n=len(roots)
    l = [roots[k] for k in range(n) if k in v.f and v.f[k]]
    b = prod([root*root-N for root in l])
    a = prod([root for root in l])
    return (a,intsqrt(b))
示例#56
0
def find_a_and_b(v, roots, N):
    '''
    Input: 
     - a {0,1,..., n-1}-vector v over GF(2) where n = len(roots)
     - a list roots of integers
     - an integer N to factor
    Output:
      a pair (a,b) of integers
      such that a*a-b*b is a multiple of N
      (if v is correctly chosen)
    '''
    alist = [roots[i] for i in v.D if v[i] == one]
    a = prod(alist)
    c = prod({x * x - N for x in alist})
    b = intsqrt(c)
    return (a, b)
示例#57
0
def find_a_and_b(v, roots, N):
    '''
    Input: 
     - a {0,1,..., n-1}-vector v over GF(2) where n = len(roots)
     - a list roots of integers
     - an integer N to factor
    Output:
      a pair (a,b) of integers
      such that a*a-b*b is a multiple of N
      (if v is correctly chosen)
    '''
    alist = [roots[index] for index in range(len(roots)) if v[index] == one]
    ##print(alist)
    a = prod(alist)
    b = intsqrt(prod([root**2-N for root in alist]))
    return (a,b)