Po9. Took asa clim.

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...
icon
Related questions
Question

Po9. Took asa clim. 

 

||||||
For positive integer n and given integer a that satisfies gcd(a, n) = 1,
the order of a modulo n is the smallest positive integer k that satisfies
pow (a, k) % n = 1. In other words, (a^k) = 1 (mod n).
Order of certain number may or may not be exist. If so, return -1.
def find_order(a, n):
||||||
Find order for positive integer n and given integer a that satisfies gcd(a, n) = 1.
Time complexity O(nlog(n))
if (a
1) & (n
1):
# Exception Handeling: 1 is the order of of 1
return 1
==
if math.gcd(a, n) != 1:
print ("a and n should be relative prime!")
return -1
for i in range(1, n):
if pow(a, i) % n == 1:
return i
return -1
==
Euler's totient function, also known as phi-function (n),
counts the number of integers between 1 and n inclusive,
which are coprime to n.
(Two numbers are coprime if their greatest common divisor (GCD) equals 1).
Code from /algorithms/maths/euler_totient.py, written by 'goswami-rahul'
def euler_totient(n):
'Euler's totient function or Phi function.
||||||
Time Complexity: O(sqrt(n))."
result = n
for i in range(2, int(n** 0.5) + 1):
if n % i == 0:
while n % i == 0:
n//=i
result = result // i
if n > 1:
result result // n
return result
For positive integer n and given integer a that satisfies gcd(a, n) = 1,
a is the primitive root of n, if a's order k for n satisfies k = o(n).
Primitive roots of certain number may or may not exist.
If so, return empty list.
def find_primitive_root(n):
if n == 1:
# Exception Handeling : 0 is the only primitive root of
return [0]
phi = euler_totient(n)
p_root_list =
||||||
It will return every primitive roots of n.
for i in range (1, n):
#To have order, a and n must be relative prime with each other.
if math.gcd(i, n) == 1:
order = find_order(i, n)
if order == phi:
Transcribed Image Text:|||||| For positive integer n and given integer a that satisfies gcd(a, n) = 1, the order of a modulo n is the smallest positive integer k that satisfies pow (a, k) % n = 1. In other words, (a^k) = 1 (mod n). Order of certain number may or may not be exist. If so, return -1. def find_order(a, n): |||||| Find order for positive integer n and given integer a that satisfies gcd(a, n) = 1. Time complexity O(nlog(n)) if (a 1) & (n 1): # Exception Handeling: 1 is the order of of 1 return 1 == if math.gcd(a, n) != 1: print ("a and n should be relative prime!") return -1 for i in range(1, n): if pow(a, i) % n == 1: return i return -1 == Euler's totient function, also known as phi-function (n), counts the number of integers between 1 and n inclusive, which are coprime to n. (Two numbers are coprime if their greatest common divisor (GCD) equals 1). Code from /algorithms/maths/euler_totient.py, written by 'goswami-rahul' def euler_totient(n): 'Euler's totient function or Phi function. |||||| Time Complexity: O(sqrt(n))." result = n for i in range(2, int(n** 0.5) + 1): if n % i == 0: while n % i == 0: n//=i result = result // i if n > 1: result result // n return result For positive integer n and given integer a that satisfies gcd(a, n) = 1, a is the primitive root of n, if a's order k for n satisfies k = o(n). Primitive roots of certain number may or may not exist. If so, return empty list. def find_primitive_root(n): if n == 1: # Exception Handeling : 0 is the only primitive root of return [0] phi = euler_totient(n) p_root_list = |||||| It will return every primitive roots of n. for i in range (1, n): #To have order, a and n must be relative prime with each other. if math.gcd(i, n) == 1: order = find_order(i, n) if order == phi:
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
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 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)
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
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY