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
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)
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
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)
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)
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)))
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)))
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)
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)
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)
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))
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)
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)
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 = [n for i, n in enumerate(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)
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[x] for x in v.D if v[x] != 0] a = prod(alist) c = prod(map(lambda x: x*x-N, alist)) b = intsqrt(c) return (a, b)
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 = [n for i, n in enumerate(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)
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[s] for s in v.D if getitem(v,s) != 0] a = prod(alist) c = prod([k**2 - N for k in alist]) b = intsqrt(c) assert b**2 == c return (a,b)
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[root] for root in v.D if v[root] == one ] # create list of roots corresponding to the nonzero entries of the vector v a = prod( alist ) c = prod({ x*x-N for x in alist }) b = intsqrt(c) assert b*b == c return (a, b)
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) ''' 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)
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[k] for k,v in v.f.items() if v == one ] a = prod(alist) clist = [x*x - N for x in alist] c = prod(clist) b = intsqrt(c) return (a,b) pass
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) ''' 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)
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 = [key for (key, val) in v.f.items() if val != 0 and key in roots] # alist = [root for root in roots if v[root] != 0] alist = [roots[key] for key,val in v.f.items() if val != 0] a = prod(alist) c = prod([x*x-N for x in alist]) b = intsqrt(c) assert b*b == c return (a,b)
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 = [key for (key, val) in v.f.items() if val != 0 and key in roots] # alist = [root for root in roots if v[root] != 0] alist = [roots[key] for key, val in v.f.items() if val != 0] a = prod(alist) c = prod([x * x - N for x in alist]) b = intsqrt(c) assert b * b == c return (a, b)
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 (i in v.f) and v.f[i] == one ] a = prod(alist) c = prod([x * x - N for x in alist]) b = intsqrt(c) #print("b*b=%d,c=%d"%(b*b,c)) assert (b * b == c) return (a, b)
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 = [] for i in v.D: if v[i] == one: alist.append(roots[i]) a = prod(alist) c = prod(x*x -N for x in alist) b = intsqrt(c) assert b*b == c return (a,b)
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) ''' tmp = [roots[i] for i in v.D if v[i] != 0] return (prod(tmp), intsqrt(prod(map(lambda x: x * x - N, tmp))))
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) return (a, b)