des_crypt_1.py 605 B

12345678910111213
  1. def _crypt_secret_to_key(secret):
  2. """convert secret to 64-bit DES key.
  3. this only uses the first 8 bytes of the secret,
  4. and discards the high 8th bit of each byte at that.
  5. a null parity bit is inserted after every 7th bit of the output.
  6. """
  7. # NOTE: this would set the parity bits correctly,
  8. # but des_encrypt_int_block() would just ignore them...
  9. ##return sum(expand_7bit(byte_elem_value(c) & 0x7f) << (56-i*8)
  10. ## for i, c in enumerate(secret[:8]))
  11. return sum((byte_elem_value(c) & 0x7f) << (57-i*8)
  12. for i, c in enumerate(secret[:8]))