def gcd_function(): print("Testing -- gcd function--") print("Using numpy.random generating {0} numbers".format(testnumber)) for n in range(testnumber): a = rd.randint(minimum, maximum) b = rd.randint(minimum, maximum) tf1 = nmtf.gcd(tf.constant(a), tf.constant(b)) nm1 = nm.gcd(a, b) print("Test {0}------------------------------".format(n + 1)) print("nmtf.gcd({0}, {1}) = {2}".format(a, b, tf1.eval())) print(" nm.gcd({0}, {1}) = {2}".format(a, b, nm1)) print("")
def generateStarDict(limit): """generate a dictionary representing all possible irregular star polygons""" possibleStars = {} for pointKey in range(5,limit): stepList = [] for step in range(2, int(math.ceil(float(pointKey)/2))): if (numbthy.gcd(pointKey, step) == 1): stepList.append(step) if len(stepList) != 0: possibleStars[pointKey] = stepList return possibleStars
def carmichael_lambda_with_list(n, factors): """carmichael_lambda(n) - Compute Carmichael's Lambda function of n - the smallest exponent e such that b**e = 1 for all b coprime to n. Otherwise defined as the exponent of the group of integers mod n.""" # SAGE equivalent is sage.crypto.util.carmichael_lambda(n) if n == 1: return 1 if n <= 0: raise ValueError( "*** Error ***: Input n for carmichael_lambda(n) must be a positive integer." ) # The gcd of (p**(e-1))*(p-1) for each prime factor p with multiplicity e (exception is p=2). def _carmichael_lambda_primepow(theprime, thepow): if ((theprime == 2) and (thepow >= 3)): return (2**(thepow - 2)) # Z_(2**e) is not cyclic for e>=3 else: return (theprime - 1) * (theprime**(thepow - 1)) return functools.reduce( lambda accum, x: (accum * x) // numbthy.gcd(accum, x), tuple(_carmichael_lambda_primepow(*primepow) for primepow in factors), 1)
def test_gcd(self): for testcase in ((1, 1, 1), (-1, 1, 1), (6, 0, 6), (0, 6, 6), (6, 6, 6), (1234, 5678, 2), (12345675, 34567890, 2469135)): self.assertEqual(numbthy.gcd(testcase[0], testcase[1]), testcase[2])
if ((a)**(n-1))%n==1: return True why=input('Do you need generated variables? y or n? ') while why!='y' and why!='n': why=input('Do you need generated variables? y or n? ') if why=='y': MIN=int(input("Minimum limit for the size of p & q: ")) MAX=int(input("Maximum limit for the size of p & q: ")) varzn=list(range(MIN+1, MAX+1)) lisln=[] vara=0 while vara!=len(varzn): varpm=varzn[vara] varav=3 avar=1 while avar==1: if gcd(varav, avar)==1: avar=varav else: varav=varav+1 if isprime(varpm, avar): lisln.append(varpm) vara=vara+1 print(lisln) #generate list of primes varp=choice(lisln) varq=choice(lisln) while varp==varq: varq=choice(lisln) #generate p & q
def main(): print gcd(25, 195)
t.join() print "Exiting Main Thread" sparse = numpy.matrix(scipy.transpose(sparse)) nulls = null(sparse) nulls = numpy.hsplit(nulls,nulls.shape[1]) xt = 1 yt = 1 print "XY length:",len(XY) print "sparse size:",sparse.shape print "nulls size:",len(nulls),",",len(nulls[0]) for j in range(0,len(nulls)): for i in range(0,nulls[j].size): if(nulls[j][i] <> 0): xt = xt * XY[i][0] yt = yt * XY[i][1] xt = xt % n yt = yt % n #print "gcd(",xt,"+",yt,",",n,") = ",numbthy.gcd((xt+yt),n) #print "gcd(-,",n,") = ",numbthy.gcd((xt-yt),n) gcd = numbthy.gcd(xt+yt,n) if(gcd <> 1 and gcd <> n): print "WE HAVE A WINNER!: ",gcd,"*",n/gcd #print "" xt = 1 yt = 1 #print nulls[1]