Question: MD 5 x 3 with = = = = = MD 5 x 3 is a block cipher that has a 3 - round Feistel
MDxwith
MDx is a block cipher that has a round Feistel structure and its round function is based on the MD hash function. The block size of MDx is bytes and its key length is bits bytes The encryption operation is illustrated in the figure below, where means concatenation of byte strings and denotes the XOR operation:
X LR
L R
K
MD
K
K
MD
K
K
MD
K
L R
Y LR
The input block X is first divided into halves, L and R bytes each. The right half R is hashed together with the first bytes K K of the key see figure the result MDKRK is XORed with the left half L and then the two halves are swapped. This makes up one round. The same operation is repeated in the remaining rounds, except that the swap of the two halves is omitted at the end of the last round, and each round uses the next bytes from the key, ie K K and K K We obtain the output Y by concatenating the two halves at the end.
A Python implementation of MDx is provided for your convenience in mdxpy It is written in Python and it uses the MD implementation and string XORing from the PyCryptodome package as a dependence.
The following test plaintext block without apostrophes
THISISATESTINPUTFORMDX
was encrypted with an unknown key, and the resulting ciphertext block in hex format is
febaeecfbadcaeebcbeafecafdbf
Break the cipher and figure out the byte key!
### Note
As the round function of MDx is based on MD you need to install PyCryptodome in order to use the mdxpy script or the RF function from it To install PyCryptodome, run
bash
pip install pycryptodome
Hint:
Hints for challenge MDx
A key observation is that the rounds of MDx use independent subsets of the key: the first round uses the first bytes of the key, the second round uses the next bytes, and finally, the third round uses the last bytes of the key. Also, by looking at the internal structure of the cipher, we can see that
L MDKRK L MDKRK
where L R L R are known as LR is the test plaintex block and LR is the corresponding ciphertext block
We can mount a meetinthemiddle attack and determine K K K K in the following way: First, we compute and store L MDKRK for all possible values of K K Then, we compute L MDKRK for all possible values of K K and for each computed value, we check if it is among the previously computed values of L MDKRK When a match is found, we have both the right K K and the right K K
The remianing bytes K K can be found by brute force...
mdxpy:
from Crypto.Hash import MD
from Crypto.Util.strxor import strxor
class TypeErrorException:
def initself message:
self.message message
class LengthErrorException:
def initself message:
self.message message
def RFL R RK:
md MDnew
mdupdateRK:RRK:
return strxorL mddigest R
def ENCX K:
if typeK bytes:
raise TypeErrorKey must be of type bytes!"
return
if lenK:
raise LengthErrorKey length must be of length bytes!"
return
if typeX bytes:
raise TypeErrorInput block must be of type bytes!"
return
if lenX:
raise LengthErrorBlock length must be of length bytes!"
return
K K:
K K:
K K:
L R X: X:
L R RFL R K
L R R L
L R RFL R K
L R R L
L R RFL R K
Y L R
return Y
def DECY K:
if typeK bytes:
raise TypeErrorKey must be of type bytes!"
return
if lenK:
raise LengthErrorKey length must be of length bytes!"
return
if typeY bytes:
raise TypeErrorInput block must be of type bytes!"
return
if lenY:
raise LengthErrorBlock length must be of length bytes!"
return
K K:
K K:
K K:
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
