Menu

[Solved]Please Solve Functions Problem Implement Algorithm Computing Square Roots Congruence Class Q37081980

Please solve the functions

In this problem you will implement an algorithm for computingall the square roots of a congruence class in ℤ/nℤ, given acomplete factorization of n into its distinct prime factor powers(assuming all the prime factors are in 3 + 4ℤ).

a) Implement a Python function sqrtsPrime(a, p) that takes twoarguments: an integer a and a prime number p. You may assume that aand p are coprime. If p is not in 3 + 4ℤ or a has no square rootsin ℤ/pℤ, the function should return None. Otherwise, it shouldreturn the two congruence classes in ℤ/pℤ that solve the followingequation:

x2 ≡ a (mod p)

>>> sqrtsPrime(2, 7)

(3, 4)

>>> sqrtsPrime(5, 7) # 5 has no square roots

None

>>> sqrtsPrime(5, 17) # 17 mod 4 =/= 3

None

>>> sqrtsPrime(763472161, 5754853343)

(27631, 5754825712)

b) Implement a Python function sqrtsPrimePower(a, p, k) thattakes three arguments: an integer a, a prime number p, and apositive integer k. You may assume that a and p are coprime. If pis not in 3 + 4ℤ or a has no square roots in ℤ/pkℤ, the functionshould return None. Otherwise, it should return the congruenceclasses in ℤ/pkℤ that solve the following equation:

x2 ≡ a (mod p2 )

>>> sqrtsPrimePower(2, 7, 2)

(10, 39)

>>> sqrtsPrimePower(763472161, 5754853343, 4)

(27631, 1096824245608362247285266960246506343570)

c) Implement a Python function equation: x2 ≡ a (mod n) sqrts(a,pks) that takes two arguments: an integer a and a list of tuplespks in which each tuple is a distinct positive prime number pairedwith a positive integer power. You may assume that a and n arecoprime. You may assume that all the primes in pks are in 3 + ℤ/4ℤ(if any are not, the function should return None). Let n be theproduct of all the prime powers in the list pks. Then the functionshould return a set of all the distinct square roots of a in ℤ/nℤthat are solutions to the following equation:

x2 ≡ a (mod n)

Here is a helper function

def combinations(ls):

if len(ls) == 0:

return [[]]

else:

return [ [x]+l for x in ls[0] for l in combinations(ls[1:])]

Expert Answer


Answer to Please solve the functions In this problem you will implement an algorithm for computing all the square roots of a congr… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *