0

I am in the process of implementing Wikipedia's pseudocode for the MD5 hashing algorithm. It includes several operations called "leftrotate," which I took to mean "shift left." However, when I implement the code, everything appears to work up until the left shifts. I'm not certain that this is the correct choice for this implementation, and what I am doing wrong to get the errors, or if I'm even approaching this implementation correctly.

# Process the message in successive 512-bit chunks:
binaryArray = [binary[i:i+512] for i in range(0, len(binary), 512)]
for chunk in binaryArray:
    M = [int(chunk[i:i+32]) for i in range(0,len(chunk),32)]
    A = a0
    B = b0
    C = c0
    D = d0

    for i in list(range(0,64)):
        if i >= 0 and i <= 15:
            F = (B&C)|((~B)&D)
            g = i
        elif i >= 16 and i <=31:
            F = (D&B)|((~D)&C)
            g = (5*i+1)%16
        elif i >= 32 and i <= 47:
            F = (B^C)^D
            g = (3*i+5)%16
        elif i >= 48 and i <= 63:
            F = C^(B|(~D))
            g = (7*i)%16
        F = F + A + K[i] + M[g]
        A = D
        D = C
        C = B + (F<<s[i]) #This is where the error occurs
    a0 = a0 + A
    b0 = b0 + B
    c0 = c0 + C
    d0 = d0 + D

Expected: An output file containing the MD5 hash of a plaintext string

Getting: Errors or an empty output file

Bouja
  • 1
  • did you define a0, b0, c0 & d0 before assigning to A, B, C, D – kudeh Apr 10 '19 at 16:38
  • Yes! The question I have pertains to the line marked, because that is where the error is located. Also, I'm looking for clarification on the pseudocode term "Leftrotate," which I took to mean "Left shift" – Bouja Apr 10 '19 at 16:42
  • It's hard to make an educated guess when you don't tell us what error you get. Ideally this would be the complete error message you receive. – blubberdiblub Apr 10 '19 at 17:22
  • The fact it is a TypeError suggests you probably initialized something incorrectly. Include those for a more thorough check. – Tyler Marshall Apr 10 '19 at 17:26

0 Answers0