/gdata/tlslite/utils/TripleDES.py

http://radioappz.googlecode.com/ · Python · 26 lines · 17 code · 4 blank · 5 comment · 3 complexity · 24c967e99279244686459034c8dc012d MD5 · raw file

  1. """Abstract class for 3DES."""
  2. from compat import * #For True
  3. class TripleDES:
  4. def __init__(self, key, mode, IV, implementation):
  5. if len(key) != 24:
  6. raise ValueError()
  7. if mode != 2:
  8. raise ValueError()
  9. if len(IV) != 8:
  10. raise ValueError()
  11. self.isBlockCipher = True
  12. self.block_size = 8
  13. self.implementation = implementation
  14. self.name = "3des"
  15. #CBC-Mode encryption, returns ciphertext
  16. #WARNING: *MAY* modify the input as well
  17. def encrypt(self, plaintext):
  18. assert(len(plaintext) % 8 == 0)
  19. #CBC-Mode decryption, returns plaintext
  20. #WARNING: *MAY* modify the input as well
  21. def decrypt(self, ciphertext):
  22. assert(len(ciphertext) % 8 == 0)