vert this python code in C++ Asap. With screenshot of cod

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Convert this python code in C++ Asap. With screenshot of code and output. 

 

from random import randrange, getrandbits
def is_prime(n, k=128):
*** Test if a number is prime
Args:
n-int- the number to test
k-int- the number of tests to do
return True if n is prime
# Test if n is not even.
# But care, 2 is prime!
if n == 2 or n == 3:
return True
if n <= 1 or n % 2 == 0:
return false
#find rand s
S=0
ran-1
whiler & 1 == 0:
S += 1
r//=2
# do k tests
for _in range(k):
a = randrange(2, n-1)
x = pow(a, r, n)
if x != 1 and x != n-1:
j=1
while j<s and x != n-1:
x = pow(x, 2, n)
if x == 1:
return false
j+=1
if x !=n-1:
return false
return True
def generate prime candidate(length):
Generate an odd integer randomly
Args:
length - int - the length of the number to generate, in bits
return a integer
#generate random bits
p=getrandbits(length)
#apply a mask to set MSB and LSB to 1
pl= (1 << length - 1)|1
return p
def generate prime_number(length=1024):
Generate a prime
Args:
length -int-length of the prime to generate, in bits
return a prime
p=4
#keep generating while the primality test fail
while not is_prime(p, 128):
p = generate_prime_candidate(length)
return p
print(generate prime_number())
Transcribed Image Text:from random import randrange, getrandbits def is_prime(n, k=128): *** Test if a number is prime Args: n-int- the number to test k-int- the number of tests to do return True if n is prime # Test if n is not even. # But care, 2 is prime! if n == 2 or n == 3: return True if n <= 1 or n % 2 == 0: return false #find rand s S=0 ran-1 whiler & 1 == 0: S += 1 r//=2 # do k tests for _in range(k): a = randrange(2, n-1) x = pow(a, r, n) if x != 1 and x != n-1: j=1 while j<s and x != n-1: x = pow(x, 2, n) if x == 1: return false j+=1 if x !=n-1: return false return True def generate prime candidate(length): Generate an odd integer randomly Args: length - int - the length of the number to generate, in bits return a integer #generate random bits p=getrandbits(length) #apply a mask to set MSB and LSB to 1 pl= (1 << length - 1)|1 return p def generate prime_number(length=1024): Generate a prime Args: length -int-length of the prime to generate, in bits return a prime p=4 #keep generating while the primality test fail while not is_prime(p, 128): p = generate_prime_candidate(length) return p print(generate prime_number())
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Computational Systems
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education