Question: Create a function affineEncrypt(text, a, b) that returns the cipher text encrypted using key (a, b). You must verify that the gcd(a, 26) =
Create a function affineEncrypt(text, a, b) that returns the cipher text encrypted using key (a, b). You must verify that the gcd(a, 26) = 1 before making the encryption. If this is not the case, the function must raise a ValueError with message "The given key is invalid. The gcd(a,26) must be 1.". You may NOT use any built-in functions as part of your implementation, but you may use any functions you implemented in previous coding assignments. Please make sure to copy and paste them into this file, so that they are uploaded to CodePost when you submit your pa3.py file. []: def affineEncrypt (text, a, b): "encrypts the plaintext 'text', using an affine transformation key (a, b) INPUT: text plaintext as a string of letters a - integer satisfying ged(a, 26) = 1. Raises error if such is not the cas b-integer OUTPUT: The encrypted message as a string of characters pass
Step by Step Solution
There are 3 Steps involved in it
def gcda b while b a b b a b return a def modinversea m for x in range1 m if a x m 1 return x return ... View full answer
Get step-by-step solutions from verified subject matter experts
