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