2 import Crypto
.Cipher
.DES3
10 def new(key
,mode
=blockcipher
.MODE_ECB
,IV
=None):
11 return DES3(key
,mode
,IV
)
13 class DES3(blockcipher
.BlockCipher
):
15 """DES using pycrypto for algo en pycryptoplus for ciphermode
17 EXAMPLE (using test vectors from http://csrc.nist.gov/groups/STM/cavp/documents/des/DESMMT.pdf):
19 >>> from binascii import hexlify, unhexlify
20 >>> key = unhexlify('37ae5ebf46dff2dc0754b94f31cbb3855e7fd36dc870bfae')
21 >>> IV = unhexlify('3d1de3cc132e3b65')
22 >>> cipher = DES3.new(key, DES3.MODE_CBC, IV)
23 >>> ciphertext = cipher.encrypt(unhexlify('84401f78fe6c10876d8ea23094ea5309'))
24 >>> hexlify(ciphertext)
25 '7b1f7c7e3b1c948ebd04a75ffba7d2f5'
26 >>> decipher = DES3.new(key, DES3.MODE_CBC, IV)
27 >>> plaintext = decipher.decrypt(ciphertext)
28 >>> hexlify(plaintext)
29 '84401f78fe6c10876d8ea23094ea5309'
31 def __init__(self
,key
,mode
,IV
):
32 self
.cipher
= Crypto
.Cipher
.DES3
.new(key
)
33 self
.blocksize
= Crypto
.Cipher
.DES3
.block_size
34 blockcipher
.BlockCipher
.__init
__(self
,key
,mode
,IV
)
40 if __name__
== "__main__":