Question: Introduction Important: Before starting this assignment, it helps to have an understanding of the connection between decimal, hexadecimal, and binary numbers. To do that, review

Introduction
Important: Before starting this assignment, it helps to have an understanding of the connection between
decimal, hexadecimal, and binary numbers. To do that, review the Hexadecimal Notation PDF darr (view in
presentation mode for the best experience).
That is attached ,Once you have done this, please read the homework requirements below.
In Module 3, we introduced the key(w,P,k) version of a block cipher algorithm that encrypts five bits at a time by
taking the input binary plaintext x and first computing an XOR of it with a five-bit string w, then applying apermutation P to the result of the previous step, and finally multiplying this result by an odd number k modulo This can be represented as follows:
binary ciphertext, y=ek(P(xo+w)) Because the number of bits we encrypt per block is 5, the block size B=5. Hence, we can further generalize this block cipher algorithm to encrypt B bits at a time, with the final operation being a multiplication by k modulo 2B.
We define a python implementation of this algorithm that encrypts an arbitrary length plaintext input x as the function encrypt(x,B,w,P,k where the function parameters are as defined above. The function returns the encrypted ciphertext Y. The algorithm this function implements is described below.
Algorithm encrypt(X,w,P,k) compute B from w or P split plaintext X into N chunks of exactly B bits length, first left padding X with O's if necessary ciphertext Y= empty
repeat N times for each chunk x:
y = block_encrypt(x,w,P,k), where block_encrypt(x,w,P,k) implements }\mp@subsup{e}{k}{}(P(x\oplusw)
Y+=y
return Y
The arbitrary permutation P is represented as an array with its values indicating the new permuted positions in
x' of the bits in x. So, the bit at position i in the permuted string x' is the bit that was at position P[i] in the input
x. Note, for simplicity and in this step only, we consider that position numbers increase from left to right for both
the input string and the permutation.
For example, let's say we have an 5-bit input string x="10110" where x[0]=1,x[1]=0,x[2]=1,x[3]=1, and x[4]=0.
Also assume a permutation array P=[4,3,1,0,2]. Then the permuted string is x'=[x[4],x[3],x[1],x[0],x[2]],
which is "01011". In other words, x'[0]=x[4],x'[1]=x[3],x'[2]=x[1],x'[3]=x[0], and x'[4]=x[2].
Instructions
You are provided with a skeletal implementation of this assignment in
P3a.py which is attached . In addition, there is a helper
file, StringConversion.py this also attached .
1) Complete the function block_encrypt(x,w,P,k given a bit string x, a bit string w, an arbitrary permutation P,
and an odd integer k. Generalize the coding of this function so that the block size B is not assumed to be 5
but is deduced from the length of x,w, or P, which should all be the same. Your multiplication of k(which is
less than 2B) should be modulo 2B.
2) Then complete the function encrypt (x,w,P,k) that takes an arbitrary length input binary string and returns the
encrypted string.
you should again deduce the block size appropriately.
3) Test this code using the test inputs embedded in comments in
P3a.py and verify that you get the expected outputs.
Your code should run correctly and be implemented efficiently.
Proper indentation and variable naming should be followed. Use meaningful variable names.
Use methods and functions as appropriate.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!