I need 3 functions added to the file:
Deciphering a Linear Cipher
In the previous assignment you wrote a function called linear that encrypts a number a using the formula
(m * a + k) mod n
For example, using m = 5, k = 11, n = 256, when you encrypt a = 10, you get the value 61. You can generate all the encrypted values by applying the linear function to the values 0...255.
>>> [ linear(5, a, 11) for a in range(0, 256) ]
[11, 16, 21, 26, 31, 36, 41, 46, 51, 56, 61, ...]
Notice that there are no duplicates. There is a one-to-one mapping between the input and output values. Therefore, the function can be reversed and a string can be both encrypted and decrypted.
To decrypt, we will need to compute the multiplicative inverse of m mod n. For example, if m = 5 and n = 26, the multiplicative inverse i obeys 5i = 1 (mod 26).
4. Write a function called multinv that computes the multiplicative inverse of m mod n. The function accepts two numbers as input (m and n) and returns the multiplicative inverse.
The multiplicative inverse can be found using the Extended GCD. Recall that the Extended GCD finds x and y such that ax + by = gcd(a, b). The multiplicative inverse of a mod b is x; the multiplicative inverse of b mod a is y.
Return the multiplicative inverse as a positive number, modulo n. That is, the number your function returns should be between 0 and n.
5. Write a function called decrypt that accepts three numbers (m, e, and k, where e is the encrypted value) and returns the corresponding decrypted value (a number). If you use m = 5 and k = 11, you should be able to decrypt each of the numbers in the chart on page 40. You can assume that n = 256.
6. Finally, write a function called lineardecipher that decrypts a byte string. It accepts a byte string as input and returns the decrypted byte string. To test this, use the linearcipher function you wrote last week to produce an encrypted string, then use lineardecipher to get the original string back.
a very experienced python developer is ready to get the job done quickly, professionally and with the lowest cost. contact me now and I'll start working right away
$10 USD in 1 day
5.0 (1 review)
1.6
1.6
3 freelancers are bidding on average $17 USD for this job