Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Here i have a python script that implements the Miller-Rabin primality test. But my code does not print the witnesses. I need a modified version
Here i have a python script that implements the Miller-Rabin primality test. But my code does not print the witnesses. I need a modified version of this code to print the witnesses for the compositeness of a number, and i need 5 Witnesses at least (Please don't change the code too much). def gcd(n,a): if (a == 0): return n else: return gcd(a,n%a) def miller_rabin(n,a): if n%2 == 0: # If n is even. return True # Return Composite. # Write n 1 = 2^k . q with q odd. x = n - 1 k = 0 while True: if x%2 == 0: x = x/2 k+=1 else: q = x q = int(q) break # Set a = a^q (mod n). a = (pow(a,q)) % n a = int(a) # If a 1 (mod n). if a == 1: return False # return Test Fails. # Loop i = 0, 1, 2, . . . , k 1 for i in range(k): # If a 1 (mod n). if a == (n-1): break # Set a = a^2 mod n. a = (pow(a,2)) % n # If a 1 (mod n). if a == (n-1): return False # return Test Fails. else: return True # Return Composite. n = input("Enter N: ") n = int(n) a = [] c = 2 for i in range(c,n): if gcd(n,i) == 1: a.append(i) if len(a) == 5: break for j in a: result = miller_rabin(n,j) if result: print(str(n) + " is a composite number and the witness is a = " + str(j)) break elif j == a[4]: print("N is probably prime") print("5 numbers that are not MillerRabin witnesses for " + str(n) + ": " + str(a))
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started