convert the
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
convert the following pseudo code into c++ code

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 c= 1 or n % 2== 0:
return False
# find r and s
S=0
r=n-1
while r&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 I-n - 1:
x = pow(x, 2, n)
if x == 1:
return False
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
return a prime
bits
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images

Recommended textbooks for you

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY