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:
for i in right:

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 1


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

  • $\begingroup$ i call P compression, as in it's compress block since it changes the block from a 48 block to a 32 $\endgroup$
    – Newbie
    Jan 14, 2015 at 21:35
  • $\begingroup$ @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!) $\endgroup$ Jan 15, 2015 at 2:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.