#7 des.set_key_odd_parity is strange

open
nobody
None
5
2006-08-18
2006-08-18
DotMG
No

def set_key_odd_parity(key):
""
for i in range(len(key)):
for k in range(7):
bit = 0
t = key[i] >> k
bit = (t ^ bit) & 0x1
key[i] = (key[i] & 0xFE) | bit

return key

Since `bit' is reinitialized to 0 inside the k-loop,
this function acts just like :

def set_key_odd_parity(key):
""
for i in range(len(key)):
bit = (key[i] >> 6) & 0x1
key[i] = (key[i] & 0xFE) | bit

return key

Discussion