write using PYTHON IDLE 3.5 be specific. please thank you Eile Edit Yew Hbtory B
ID: 3808731 • Letter: W
Question
write using PYTHON IDLE 3.5 be specific. please thank you
Eile Edit Yew Hbtory Bookmarks bols Help O labl-crypto-s1 Microsoft Word Free Sports Picks https sakai. item/11778635/group/e3dbb580-16f5-49of-aff0-88196032a87c/Labs/Lab 7 cryptog rithms -10 28 /lab7-crypto-s1 e a Search A Most visited e Getting started t b) Write a function to check for relatively prime numbers In order for the Affine cipher to work, the multiplier a must be relatively prime with the modulus m. This means that the two integers have no common factors. For example 15 and 26 have no factors in common, so 15 is an acceptable value for a, however 12 and 26 have factors in common (e.g. 20 so 12 cannot be used for a value of a. Write a function that takes as parameters two positive integers (a and m) and returns TRUE if the two numbers are relatively prime and FALSE ifthey are not relatively prime. Instructor Initials: c) Write a function to compute the Affine cipher. The input parameters for the function will be a, b, m and the plaintext. The function will return the ciphertext. This function should check to make sure that a and m are relatively prime (by calling the function above). If not, it should return a blank string. Test your function using the examples from part b above. AExplanation / Answer
Please find the answer to the first question below:
def co_prime(a,m):
factor_a = [] # empty list to store factors of a
factor_m = [] # empty list to store factors of m
if a>1 and m>1:
for i in range(2,a+1):
if a%i == 0:
factor_a.append(i) #appending factors of a in factor_a
for j in range(2,m+1):
if m%j == 0:
factor_m.append(j) #appending factors of m in factor_m
#If intersection between factor_a and factor_m is empty, then True.
if set(factor_a).intersection(factor_m) == set():
return True
else:
return False
else: # if any number is 1, then directly return True.
return True
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.