Question: I have a five part problem that builds on each part. I have to: Write the egcd function Write a function called multinv that is

I have a five part problem that builds on each part. I have to:

Write the egcd function

Write a function called multinv that is given two integers (a and n) and returns the multiplicative inverse of a mod n. Hint: call egcd(a, n) and return the first element of the tuple that you get back, modulo n.

Write a function called decrypt that accepts three numbers (c, m, and k) and returns the corresponding plaintext (p) value as a number. You can assume the modulus (n) is 256. You will need to compute the multiplicative inverse of m mod 256 to decipher c.

Write a function called decryptstring that accepts a ciphertext byte string, a multiplier (m), and shift amount (k). It returns an array of integers containing the decrypted values.

Finally, write a function called lineardecipher that accepts a ciphertext byte string, a multiplier (m), and a shift amount (k). It returns the corresponding plaintext byte string.

I have already done the first to parts, writing the egcd and multinv functions, I just need help with the other three functions.

# Part 1: Extended Euclidean Algorithm def egcd(a, b): if b == 0: return (1, 0) else: # Calculate q q = a // b # Calculate r r = a % b # Calculate (s, t) by calling egcd(b, r) (s,t) = egcd(b, r) return (t, s-q*t) # Part 2: Multiplicative Inverse def multinv(a, n): g = egcd(a, n) return g[0] % n # Part 3: Decrypt a single value def decrypt(c, m, k): ...

# Part 4: Decrypt a byte string into an array of ints def decryptstring(ciphertext, m, k): ...

# Part 5: Decrypt a byte string, returning a byte string def lineardecipher(ciphertext, m, k):

...

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!