Пример #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)
Пример #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)
Пример #3
0
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
Пример #4
0
def solve(N, primelist):
    roots, rowlist = find_candidates(N, primelist)
    M = echelon.transformation_rows(rowlist)
    index = -1
    while True:
        v = M[index:][0]
        a, b = find_a_and_b(v, roots, N)
        g = gcd(a - b, N)
        if g != 1:
            return g
        else:
            index = index - 1
Пример #5
0
def factor(N, primeset):
    roots, rowlist = find_candidates(N, primeset)
    M = transformation_rows(rowlist)
    m = rowdict2mat(M)
    a = rowdict2mat(rowlist)
    ma = mat2rowdict(m * a)
    zero_pos = [i for i in ma if ma[i] == 0 * ma[0]]

    for i in zero_pos:
        a, b = find_a_and_b(M[i], roots, N)
        factor1, factor2 = gcd(a + b, N), gcd(a - b, N)
        if factor1 * factor2 == N:
            return factor1, factor2
Пример #6
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;
Пример #7
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")
Пример #8
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
Пример #9
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
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
Пример #12
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())
Пример #13
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) 
Пример #14
0
            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
  """
    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)
Пример #15
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)
Пример #16
0
    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)
Пример #17
0

## 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)
    '''
    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)
    assert b*b ==c
    return (a,b)

## Task 5
N = 2461799993978700679
primeset = primes(10000)
roots,rowlist = find_candidates(N,primentset)
M = echelon.transformation_rows(rowlist, sorted(primeset, reverse=True)) # 320 s
for v in M[::-1]:
    a,b = find_a_and_b(v,roots,N)
    
smallest_nontrivial_divisor_of_2461799993978700679 = ...