Question: Exercise 3 : PKCS# 7 padding [ 2 0 pts ] The PKCS# 7 padding scheme is commonly used to pad irregularly - sized plaintext
Exercise : PKCS# padding pts
The PKCS# padding scheme is commonly used to pad irregularlysized plaintext messages to a specific block length before encryption, and is described in RFC The algorithm simply consists in appending the required number of bytes up to nearest multiple of the block length. The value of each appended byte is equal to the number of bytes added. The maximum length of the pad is therefore If the plaintext size is already a multiple of the block length, padding is still required. In this case, an entire block of padding bytes will be used. To remove the padding after decryption, the last byte of the decrypted ciphertext is read, which indicates how many bytes of the same value should be stripped from the end.
For this exercise, do NOT use any librarypackage in your code.
Write a function pkcsplaintext length in Python that takes a plaintext plaintext and a desired block length length as input and applies the PKCS# padding scheme. The function should return the padded input. An exception should be thrown if the block length is greater than the maximum pad length, using: raise Exception Invalid block size"
For instance, for the message "YELLOW SUBMARINE" and a block size of the output should be
"YELLOW SUBMARINEtimes times times times
Write a function validate pkcsplaintext length in Python that verifies the validity of the padding, and returns an unpadded string. The function should throw exceptions using raise ExceptionInvalid padding" when: the length of the plaintext indicates that no padding has been used; the value for the pad length is incompatible with the block length; the value of the padding bytes is incorrect. pts
Prepare a single Python file named exercisepy that contains both functions.
Make sure to use the exact exception messages given above throughout this exercise; otherwise, your function will not be evaluated properly for assessment.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
