Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 3 : PKCS# 7 padding [ 2 0 pts ] The PKCS# 7 padding scheme is commonly used to pad irregularly - sized plaintext

Exercise 3: PKCS#7 padding [20 pts]
The PKCS#7 padding scheme is commonly used to pad irregularly-sized plaintext messages to a specific block length before encryption, and is described in RFC5652. 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 255. 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 library/package in your code.
1. Write a function pkcs(plaintext, length) in Python that takes a plaintext (plaintext) and a desired block length (length) as input and applies the PKCS#7 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 20, the output should be
"YELLOW SUBMARINE)\times 04\\times 04\\times 04\\times 04".
2. Write a function validate pkcs(plaintext, length) in Python that verifies the validity of the padding, and returns an unpadded string. The function should throw exceptions using raise Exception("Invalid padding") when: 1) the length of the plaintext indicates that no padding has been used; 2) the value for the pad length is incompatible with the block length; 3) the value of the padding bytes is incorrect. [15 pts]
Prepare a single Python file named exercise3.py 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke

12th Edition International Edition

1292023422, 978-1292023427

More Books

Students also viewed these Databases questions

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago