Python decryption function help! I have these functions: 3.Write a function call
ID: 3830220 • Letter: P
Question
Python decryption function help!
I have these functions:
3.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.
# Problem 3: Decrypt a single value
def decrypt(c, m, k):
ciphertext = c * m
plaintext = (ciphertext**k)%256
return plaintext
4.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.
# Problem 4: Decrypt a byte string into an array of ints
def decryptstring(ciphertext, m, k):
...
5.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.
# Problem 5: Decrypt a byte string, returning a byte string
def lineardecipher(ciphertext, m, k):
...
I already wrote the first but I need help with the last two functions.
Explanation / Answer
PROGRAM CODE:
def decrypt(c, m, k):
ciphertext = c * m
plaintext = (ciphertext**k)%256
return plaintext
def decryptstring(ciphertext, m, k):
list = []
for i in range(0, len(ciphertext)):
list[i] = decrypt(ciphertext[i], m, k)
return list
def lineardecipher(ciphertext, m, k):
text = "";
for i in range(0, len(ciphertext)):
text += decrypt(ciphertext[i], m, k)
return text
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.