Ejemplo n.º 1
0
def solve():
    N = 2461799993978700679
    primelist = primes(10000)
    roots, rowlist = find_candidates(N, primelist)
    M = echelon.transformation_rows(rowlist)
    for v in reversed(M):
        a,b = find_a_and_b(v, roots, N)
        if gcd(a-b,N) != 1:
            return gcd(a-b,N)
Ejemplo n.º 2
0
def solve():
    N = 2461799993978700679
    primelist = primes(10000)
    roots, rowlist = find_candidates(N, primelist)
    M = echelon.transformation_rows(rowlist)
    for v in reversed(M):
        a, b = find_a_and_b(v, roots, N)
        if gcd(a - b, N) != 1:
            return gcd(a - b, N)
Ejemplo n.º 3
0
def find():
    N=2461799993978700679
    primelist=primes(10000)
    (roots, rowlist) = find_candidates(N, primelist)
    M=echelon.transformation_rows(rowlist)
    counter=1
    while True:
        v=M[-1*counter]
        counter = counter+1
        (a,b)=find_a_and_b(v, roots, N)
        print(gcd(a-b, N))
        if gcd(a-b, N)>1:
            break;
Ejemplo n.º 4
0
def find_non_trivial_div(N):
    pr_lst = primes(10000)
    roots, rowlist = find_candidates(N, pr_lst)
    M = echelon.transformation_rows(rowlist, sorted(pr_lst, reverse=True))
    A = rowdict2mat(rowlist)
    for v in reversed(M):
        if not is_zero_vec(v*A):
            raise Exception("Unable to find non-trivial div")
        a, b = find_a_and_b(v, roots, N)
        div_candidate = gcd(a - b, N)
        if div_candidate != 1:
            return div_candidate
    raise Exception("Unable to find non-trivial div")
Ejemplo n.º 5
0
def task5(N, p):
    primelist = primes(p)
    #N = 2461799993978700679
    roots, rowlist = find_candidates(N, primelist)
    M = echelon.transformation_rows(rowlist)
    #print(M)
    for r in reversed(range(len(M))):
        v = M[r]
        a, b = find_a_and_b(v, roots, N)
        f = gcd(a - b, N)
        if (f != 1 and f != N):
            return f

    return -1
Ejemplo n.º 6
0
def factor(N):
    primeset = primes(10000)
    print("primeset len:", len(primeset))
    roots, rowlist = find_candidates(N, primeset)
    print("find candidates done.")

    M = echelon.transformation_rows(rowlist)
    print("transformation done.")

    for v in reversed(M):
        print(v)
        a, b = find_a_and_b(v, roots, N)
        print("a: ", a, "b: ", b)
        if N % (a - b) == 0 and a - b != 1 and a - b != N:
            return a - b
Ejemplo n.º 7
0
def problem5():
    N = 2461799993978700679
    print('generando primelist ...')
    primelist = primes(10000)
    print('buscando candidatos ...')
    roots, rowlist = find_candidates(N, primelist)
    print('calculando M ...')
    M = echelon.transformation_rows(rowlist)
    print('extraccion de v ...')
    v = M[-2]
    print('busqueda de a y b ...')
    a, b = find_a_and_b(v, roots, N)
    amb = a - b
    print('buscando gcd ...')
    print(gcd(amb, N))
def factor(N):
    primeset = primes(10000)
    print("primeset len:", len(primeset))
    roots, rowlist = find_candidates(N, primeset)
    print("find candidates done.")
    
    M = echelon.transformation_rows(rowlist)
    print("transformation done.")
    
    for v in reversed(M):
        print(v)
        a, b = find_a_and_b(v, roots, N)
        print("a: ", a, "b: ", b)
        if N%(a-b) == 0 and a-b != 1 and a-b != N:
            return a-b
def factor(N):
    ret = []
    print('N=', N)
    primeset = primes(10000)
    primelist = list(primeset)
    #shuffle(primelist)
    primelist.sort(reverse=True)
    roots, rowlist = find_candidates(N, primeset)
    M = echelon.transformation_rows(rowlist)
    for i in reversed(range(len(M))):
        a, b = find_a_and_b(M[i], roots, N)
        if gcd(a-b, N) != 1:
            print('find ', gcd(a-b, N))
            ret.append(gcd(a-b, N))
            N //= gcd(a-b, N)
        if N == 1:
            break
    return ret
Ejemplo n.º 10
0
# rowIndex = -2
# roots, rowlist = find_candidates(N, primes(32))
# M = transformation_rows(rowlist)
# print(roots, M[rowIndex])

# a,b = find_a_and_b(M[rowIndex], roots, N)
# print(a, b, a-b, gcd(a-b, N), N/gcd(a-b, N))

## Task 5
# N = 2461799993978700679
# rowIndex = -1
# roots, rowlist = find_candidates(N, primes(1000))
# M = transformation_rows(rowlist)
# print(roots, M[rowIndex])

# a,b = find_a_and_b(M[rowIndex], roots, N)
# print(a, b, a-b, gcd(a-b, N), N/gcd(a-b, N))

smallest_nontrivial_divisor_of_2461799993978700679 = 1230926561

print(datetime.now().time())
N = 20672783502493917028427
rowIndex = -1
roots, rowlist = find_candidates(N, primes(1000))
M = transformation_rows(rowlist)
print(roots, M[rowIndex])

a, b = find_a_and_b(M[rowIndex], roots, N)
print(a, b, a - b, gcd(a - b, N), N / gcd(a - b, N))
print(datetime.now().time())
Ejemplo n.º 11
0
g = gcd(a-b, N)
#print(g)
#print (N%g == 0)

r = 99083208324108213
s = 54982011313211212
t = 23239982309329329
a = r*s
b = s*t
d = gcd(a, b)
#print(a%d == 0)
#print(b%d == 0)
#print(d > s)


R,L = find_candidates(2419, primes(32))
#R = result[0]
#L = result[1]
for i in range(len(L)):
    print('%s, %s' % (R[i], L[i].f))

M = transformation_rows(L)
print(M)
v = M[-1]
print(v.f)

a, b = find_a_and_b(v, R, 2419)
print(a)
print(b)

print(sntd)
Ejemplo n.º 12
0
        True
    '''
    roots, rowlist, x = [], [], intsqrt(N) + 1
    while True:
        x += 1
        factors = dumb_factor(x**2 - N, primeset)
        if not factors:
            continue
        roots += [x]
        rowlist += [make_Vec(primeset, factors)]
        if len(roots) == len(primeset) + 1:
            return (roots, rowlist)

if PRINT_BOOK_TESTS:
    print("== Task 7.8.7 ==")
    print(find_candidates(2419, primes(32)))
    print(len(primes(32)))

## Task 4
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]
Ejemplo n.º 13
0
def problem3():
    a, b = find_candidates(2419, primes(32))
    print(a)
    print(b)
Ejemplo n.º 14
0
    x = factoring_support.intsqrt(N) + 2
    while (len(roots) < len(primeset) + 1):
        candidate = x * x - N
        if can_be_factored_completely(candidate, primeset):
            roots.append(x)
            rowlist.append(
                make_Vec(primeset,
                         factoring_support.dumb_factor(candidate, primeset)))
        x += 1

    return roots, rowlist


N = 2419
test_roots, test_rows = find_candidates(N, factoring_support.primes(32))

test_divisor = gcd((53 * 77) - (2 * 3 * 3 * 5 * 13), N)
assert ((N % test_divisor) == 0)

M = echelon.transformation_rows(test_rows)


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
Ejemplo n.º 15
0
     - 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.f if v[i] == one]
    a = prod(alist)
    c = prod(x * x - N for x in alist)
    b = intsqrt(c)
    if b * b == c:
        return a, b
    return None


## Task 5
def factor_woojoo(N, primeset):
    roots, rowlist = find_candidates(N, primeset)
    M = echelon.transformation_rows(rowlist, sorted(primeset, reverse=True))
    rank = independence.rank(rowlist)
    for i in range(len(M) - 1, rank - 1, -1):
        a, b = find_a_and_b(M[i], roots, N)
        ans = gcd(a - b, N)
        if ans > 1:
            return ans
    return None


primeset = primes(10000)
smallest_nontrivial_divisor_of_2461799993978700679 = factor_woojoo(
    2461799993978700679, primeset)
Ejemplo n.º 16
0
    Output:
      a pair (a,b) of integers
      such that a*a-b*b is a multiple of N
      (if v is correctly chosen)
    '''
    a_factors = [roots[i] for i in v.f if v[i] == one]
    a = prod(a_factors)
    c_factors = [x * x - N for x in a_factors]
    c = prod(c_factors)
    b = intsqrt(c)
    assert b * b == c, "a*a - N is not a perfect square"
    return (a, b)


## Task 5
if __name__ == "__main__":
    primelist = primes(10000)
    N = 2461799993978700679
    (roots, rowlist) = find_candidates(N, primelist)
    M = echelon.transformation_rows(rowlist, sorted(primelist, reverse=True))

    divisor = N  #starting at the largest possible divisor
    for i in range(2, 20):
        v = M[-i]
        (a, b) = find_a_and_b(v, roots, N)
        x = gcd(a - b, N)
        if x < divisor and x != 1: divisor = x
        if N // x < divisor and x != N: divisor = N // x
    print("The smallest found divisor is: {0}".format(divisor))
smallest_nontrivial_divisor_of_2461799993978700679 = 1230926561
Ejemplo n.º 17
0
      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)

v = Vec({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},{0: 0, 1: one, 2: one, 4: 0, 5: one, 11: one})
N = 2419
roots = [51, 52, 53, 58, 61, 62, 63, 67, 68, 71, 77, 79]
##print(find_a_and_b(v, roots, N))
v = Vec({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11},{0: 0, 1: 0, 10: one, 2: one})
N = 2419
roots = [51, 52, 53, 58, 61, 62, 63, 67, 68, 71, 77, 79]
##print(find_a_and_b(v, roots, N))


## Task 5
N = 2461799993978700679
##N=243127
primeset = primes(10000)
candidates = find_candidates(N, primeset)
transformation_matrix = echelon.transformation_rows(candidates[1])
(a,b) = find_a_and_b(transformation_matrix[-1], candidates[0], N)
print(a,b)
print(gcd(a-b, N))
smallest_nontrivial_divisor_of_2461799993978700679 = gcd(a-b, N) 
Ejemplo n.º 18
0
      a pair (a,b) of integers
      such that a*a-b*b is a multiple of N
      (if v is correctly chosen)
    '''
    a_factors = [roots[i] for i in v.f if v[i] == one] 
    a = prod(a_factors)
    c_factors = [x*x - N for x in a_factors]
    c = prod(c_factors)
    b = intsqrt(c)
    assert b*b == c, "a*a - N is not a perfect square"
    return(a, b)


## Task 5
if __name__ == "__main__":
    primelist = primes(10000)
    N = 2461799993978700679
    (roots, rowlist) = find_candidates(N, primelist)
    M = echelon.transformation_rows(rowlist, sorted(primelist, reverse=True))

    divisor = N #starting at the largest possible divisor
    for i in range(2,20):
        v = M[-i]
        (a, b) = find_a_and_b(v, roots, N)
        x = gcd(a-b, N)
        if x < divisor and x != 1: divisor = x
        if N//x < divisor and x != N: divisor = N//x
    print("The smallest found divisor is: {0}".format(divisor))
smallest_nontrivial_divisor_of_2461799993978700679 = 1230926561

Ejemplo n.º 19
0
                   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)+1
    while len(roots) < len(primeset)+1:
        x+=1
        factors = dumb_factor(x*x -N, primeset)
        if len(factors) > 0:
            roots.append(x)
            rowlist.append(make_Vec(primeset, factors))
    return (roots,rowlist)

primeset = primes(32)    
N = 2419
(roots,rowlist) = find_candidates(N, primeset)



## Task 4
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
Ejemplo n.º 20
0
print(root_method(55))
print(root_method(77))
print(root_method(146771))
# print(root_method(118))

print(gcd(23, 15))
N = 367160330145890434494322103
a = 67469780066325164
b = 9429601150488992
c = a * a - b * b
print(gcd(a - b, N))

print(make_Vec({2, 3, 5, 7, 11}, [(3, 1)]))
print(make_Vec({2, 3, 5, 7, 11}, [(2, 17), (3, 0), (5, 1), (11, 3)]))
print(find_candidates(2419, primes(32))[1])

A = listlist2mat([[0, 2, 3, 4, 5], [0, 0, 0, 3, 2], [1, 2, 3, 4, 5],
                  [0, 0, 0, 6, 7], [0, 0, 0, 9, 8]])
print(A)
M = transformation(A)
print(M)
# print(M * A)
print(M * A)
# print()
# print(listlist2mat([[0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [1, 0, 0, 0, 0], [0, 0, 2, 1, 0], [0, 0, 3.004, 0.667, 1]]) * (M * A))
print(
    row_reduce([
        list2vec([one, one, 0, 0]),
        list2vec([one, 0, one, 0]),
        list2vec([0, one, one, one]),
Ejemplo n.º 21
0
#the interesting part ...
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 factors == []:
            pass
        else:
            roots.append(x)
            rowlist.append(make_Vec(primeset, factors))
        x += 1
    return roots, rowlist

roots, rowlist = find_candidates(2419,primes(32))

#7.8.8
a = 53 * 77
b = 2 * (3 **2 ) * 5 * 13
divisor = gcd(a -b, 2419)
print(divisor) #41
assert 2419%divisor == 0

c = 52 * 67 * 71
print(c)
d = 2 * (3**2) * 5 * 19 * 23
print(d,'cd')
divisor2 = gcd(2419,c-d)
print(divisor2) #returned 2419, which is valid I think, b/c that just means that c-d
#is a multiple of 2149 c-d == 86 * 2419