Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

5a. (10 pts) Write a function named decrypt, which takes a string s and a dictio

ID: 3734618 • Letter: 5

Question

5a. (10 pts) Write a function named decrypt, which takes a string s and a dictionary d where each key in the dictionary is a string word associated with a secret code as its key. This function should return the list of all possible ways (order it returns it in doesn't matter) in which the string s can be decoded by splitting it into secret codes and separating the corresponding words of the decoded word with spaces. For instance, calling decrypt('turing, 'turing': 'A', 'tur': 'B', 'ng 'C', 'tu': 'D', 'ring': 'E', 'ri': 'F' ng': G)) returns 'A, D E, D F G', B c']. These results are computed by first starting with the whole string 'turing', which has a corresponding secret code. Then consider substrings 't' and 'uring, which don't have any secret codes, and then , tu, and ring', etc. Note that the the substrings 'tu' and 'ring' produce 'D E', but also produces D F G' since there is an alternative decoding for 'ring' by splitting it up into the substrings 'ri' and 'ng' Accomplishing this can easily be done via recursion. There are no restrictions in how you write this function you may use any combination of loops, variables, lists, as desired. Of course, you will find it necessary to use recursion. def decrypt(s: str, d: (str: str) - [str]:

Explanation / Answer

CODE:

def decrypt(my_key=KEY, my_iv=IV, encryptText=encrypttext):

        key = binascii.unhexlify(my_key)

        iv = binascii.unhexlify(my_iv)

        encryptor = AES.new(key, AES.MODE_CBC, iv, segment_size=128) # Initialize encryptor

        result = encryptor.decrypt(binascii.a2b_hex(encryptText))

        padder = PKCS7Padder()

        decryptText=padder.decode(result)

           return {

          "plain": encryptText,

          "key": binascii.hexlify(key)

          "iv": binascii.hexlify(iv),

          "decryptedTest": decryptText

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote