示例#1
0
def prime_factor():

    number = input("Number: ")
    factors = factor(number)
    prime_factors = []

    for number in factors:
        # test for primality
        test = factor(number)
        if len(test) == 2:
            prime_factors.append(number)

    print(prime_factors)
    return prime_factors
def is_primiitve(number,mod):
	factorsOfToitent = factor(mod-1)
	for prime in factorsOfToitent:
		for exp in xrange(1,factorsOfToitent[prime]+1):
		  if prime**exp == mod-1:
		  	return True
		  if number**(prime**exp)%mod == 1:
		  	return False
	return True
示例#3
0
def abelians(n):
    """Returns an iterator over all abelian groups of order `n` paired with
       lists of their invariant factors"""
    if n < 1:
        return
    elif n == 1:
        yield (Trivial, [])
    else:
        vals = []
        for (p,k) in factor(n):
            vals.append([[p**i for i in part] for part in partitions(k)])
        for xs in itertools.product(*vals):
            xs2 = reduce(lambda a,b: itertools.starmap(mul, izip_longest(a, b, fillvalue=1)), xs)
            yield (reduce(Direct, map(Cyclic, xs2)), xs2)
示例#4
0
 def do_classify(self):
     file_object = open('thefile2.txt', 'w')
     t_len=len(self.start)
     t_vis=[0 for i in range(t_len)]
     for i in range(t_len-1):
         if(t_vis[i]==1):
             continue
         t_vis[i]=1
         t_temp=[]
         l_temp=[]
         t_temp.append(self.start[i])
         l_temp.append(i)
         for j in range(i+1,t_len):
             if(t_vis[j]==1):
                 continue
             else:
                 #file_object.write(repr(i+1))
                 #file_object.write(" ")
                 #file_object.write(repr(j+1))
                 #print ("%d %d"%(i,j))
                 #file_object.write('\r\n')
                 #file_object.write(repr(self.start[i]))
                 #file_object.write('\r\n')
                 #file_object.write(repr(self.start[j]))
                 #file_object.write('\r\n')
                 #file_object.flush()
                 #print repr(self.start[i])
                 #print repr(self.start[j])
                 pe=prepare(self.start[i],self.start[j])
                 pe.get_lists()
                 pe.get_data()
                 fy=factor(self.start[i],self.start[j],pe.change)
                 fy.spart_1()
                 #fy.cluster()
                 #fy.get_similar()
                 print (i+1," ",j+1," ",fy.get_sim())
                 if(fy.get_same1()>=0.25):
                     t_vis[j]=1
                     t_temp.append(self.start[j])
                     l_temp.append(j)
         self.result.append(t_temp)
         self.link.append(l_temp)
     file_object.close()
示例#5
0
            l1.append(int(i.strip('\n')))
    with open(y, 'r') as f:
        for i in f.readlines():
            l2.append(int(i.strip('\n')))

    b = sorted([x * y for x in l1 for y in l2])
    return b


nums = rf('3', '4', rst=False)
s = 0
v = 0
for n in nums:
    seed = func(n, *popt)
    t1 = time.time()
    k = factor(n, seed)
    t2 = time.time()
    if k:
        s += t2 - t1
        v += 1

print('FPI %f seconds' % (s / v))

s = 0
v = 0
for n in nums:
    t1 = time.time()
    k = brute_force(n)
    t2 = time.time()
    s += t2 - t1
    v += 1
示例#6
0
t_len = len(messages)
t_vis = [0 for i in range(t_len)]
result_message = []
result_l = []
for i in range(t_len - 1):
    if (t_vis[i] == 1):
        continue
    t_vis[i] = 1
    t_temp = []
    l_temp = []
    t_temp.append(messages[i])
    l_temp.append(i)
    for j in range(i + 1, t_len):
        if (t_vis[j] == 1):
            continue
        else:
            start_one = str(messages[i].data)
            start_two = str(messages[j].data)
            pe = prepare(start_one, start_two)
            pe.get_lists()
            pe.get_data()
            fy = factor(start_one, start_two, pe.change)
            fy.spart_1()
            if (fy.get_same1() >= 0.3):
                t_vis[j] = 1
                t_temp.append(messages[j])
                l_temp.append(j)
    result_message.append(t_temp)
    result_l.append(l_temp)
    print result_l