def task784(): primeset = {2, 3, 5, 7, 11, 13} print(factoring_support.dumb_factor(12, primeset)) print(factoring_support.dumb_factor(154, primeset)) print(factoring_support.dumb_factor(2 * 3 * 3 * 3 * 11 * 11 * 13, primeset)) print(factoring_support.dumb_factor(2 * 17, primeset)) print(factoring_support.dumb_factor(2 * 3 * 5 * 7 * 19, primeset))
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)
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)
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) ''' 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)
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 = 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
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 = [] 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)
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) ''' 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)
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 = [] 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_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)
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)
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)
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)
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
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
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
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_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)
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 = [] x = intsqrt(N)+2 while len(roots) < len(primeset)+1: if len (dumb_factor(x**2-N, primeset)) != 0: roots.append(x) rowlist.append(make_Vec(primeset, dumb_factor(x**2-N, primeset))) x+=1 return (roots, rowlist)
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
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)
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 while len(roots) < len(primeset)+1: # continue until x = intsqrt(N) + i if dumb_factor( x*x - N , primeset) != []: # ask if x*x-N is unfactorable roots.append(x) # if not, then append to root list # append to rowlist a vector mapping the parity of the exponent to an element in GF2 (1 or 0) # the elements in the domain of this vec are the primes in primeset rowlist.append(make_Vec(primeset, dumb_factor( x*x-N, primeset ))) i += 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 ''' from itertools import count roots, rowlist = [], [] for x in count(intsqrt(N) + 2): to_factor = x*x - N factored = dumb_factor(to_factor, primeset) if factored: roots.append(x) rowlist.append(make_Vec(primeset, factored)) if len(roots) == len(primeset) + 1: break 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 """ roots = [] rowlist = [] for x in range(2, N): y = x + intsqrt(N) tmp = dumb_factor(y * y - N, primeset) if len(tmp) != 0: roots.append(y) rowlist.append(make_Vec(primeset, tmp)) if len(roots) >= len(primeset) + 1: break 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=[] y=0 b=0 #c = [] #d = [] c=len(primeset) +1 i =2 #j=range(i) #for x in j: # y=intsqrt(N)+x # a=dumb_factor(y*y-N,primeset) # if a!=[]: # c.append(y) # d.append(make_Vec(primeset,a)) #i=i+len(c)+len(d) #for x in range(i): #for x in primeset: while( len(roots)<=c): if i!=0 and i!=1: y=intsqrt(N)+i i = i +1 a=dumb_factor(y*y-N,primeset) if a!=[]: #c.append(y) #d.append(make_Vec(primeset,a)) roots.append(y) rowlist.append(make_Vec(primeset,a)) return (roots,rowlist)
def find_candidates(N, primeset): roots = [] rowlist = [] def can_be_factored_completely(x, primes): factors = factoring_support.dumb_factor(x, primes) return len(factors) > 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
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): test = dumb_factor(x * x - N, primeset) if len(test) > 0: roots += [x] rowlist += [make_Vec(primeset, test)] x += 1 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 = [],[] x = intsqrt(N)+2 while len(roots) <= len(primeset): test=dumb_factor(x*x-N,primeset) if len(test) > 0: roots += [x] rowlist += [make_Vec(primeset,test)] x+=1 return (roots,rowlist)
def gcd(x, y): return x if y == 0 else gcd(y, x % y) def int2GF2(x): return one if x % 2 == 1 else 0 def make_Vec(primeset, factors): d = primeset print(factors) f = dict(map(lambda x: (x[0], int2GF2(x[1])), factors)) print(f) return Vec(d, f) # N = [55,77,118,146771] # print(root_method(N[1])) # r = 12398280234912304 # s = 2752187456 #5504374912 # t = 9541094510 # a = r*s # b = s*t # print(gcd(a,b)) # print(dumb_factor(75,{2,3,5,7})) factors = {2, 3, 5, 7, 11} #print(int2GF2(3)) N = 2419 print(dumb_factor(N, factors)) print(make_Vec(factors, dumb_factor(N, factors)))
## Task 7.8.3 if PRINT_BOOK_TESTS: print("== 7.8.3 ==") n_3 = 367160330145890434494322103 a_3 = 67469780066325164 b_3 = 9429601150488992 print((a_3**2 - b_3**2) % n_3 == 0) print(gcd(n_3, a_3 - b_3)) ## Task 7.8.4 if PRINT_BOOK_TESTS: print("== 7.8.4 ==") prime_set = set([2, 3, 5, 7, 11, 13]) print(dumb_factor(12, prime_set)) print(dumb_factor(154, prime_set)) print(dumb_factor(2*3*3*3*11*11*13, prime_set)) print(dumb_factor(2*17, prime_set)) print(dumb_factor(2*3*5*7*19, prime_set)) ## Task 1 def int2GF2(i): ''' Returns one if i is odd, 0 otherwise. Input: - i: an int Output: - one if i is congruent to 1 mod 2
assert d >= s print(d, a/d, a/d * d) #holy shit Euclid was a smart cookie #7.8.3 N = 367160330145890434494322103 a = 67469780066325164 b = 9429601150488992 c = (a*a - b*b )/N print(c) print(gcd(N, a-b)) #gdc of N and a-b is 19117318483477 #7.8.4 primeset = {2,3,5,7,11,13} Ns = [12, 154, 2*3*3*3*11*11*11*13, 2*17,2*3*5*7*19] [print(dumb_factor(x, primeset)) for x in Ns] #correct answer for first 3, returned none for last two b/c 17 and 19 not in primeset #7.8.5 def int2GF2(i): if i % 2 == 0: return 0 else: return one #7.8.6 def make_Vec(primeset, factors): return Vec(primeset,{factor[0]:int2GF2(factor[1]) for factor in factors}) print(make_Vec({2,3,5,7,11},[(3,1)]))
def can_be_factored_completely(x, primes): factors = factoring_support.dumb_factor(x, primes) return len(factors) > 0