# Problem with implementing DES in python

i'm implementing DES in python and i've stumbled upon a problem i can't really find the problem, after debugging it i narrowed it down to this function, can anyone tell me if i'm implementing the DES function correctly or not?

def roundFunction(s1,j,k,l):
left = s1[0:32]
right = s1[32:]

for i in range(j,k,l):

eRight = expandBlock(right)
subKey = compressBlock(listxor(eRight, key[i]))

left = listxor(left, subKey)
left,right = swap(left,right)

left,right = swap(left,right)

result = []
for i in left:
result.append(i)
for i in right:
result.append(i)

return result


i have uploaded the whole code to this link for anyone who wants to check it out: http://codeviewer.org/view/code:49db

## 1 Answer

From what I can see, you didn't apply permutation P after compressBlock.

• i call P compression, as in it's compress block since it changes the block from a 48 block to a 32 – Newbie Jan 14 '15 at 21:35
• @Newbie: Yeah, but I looked at your code, and you don't apply the P permutation after doing the S-boxes in compressBlock. You could do that inside the function called compressBlock, or you could do it after that call in roundFunction, but it's gotta be done somewhere. (As an aside, your function names aren't terribly conducive to debugging!) – Reid Rankin Jan 15 '15 at 2:52