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


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

| improve this answer | |
  • $\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 '15 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$ – Reid Rankin Jan 15 '15 at 2:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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