git-svn-id: svn+ssh://devel.yobi.be/home/svn/CryptoPlus/trunk@6 49921240-e1b6-4d8d...
[python-cryptoplus.git] / Cipher / DES3.py
blobe2787044044001863bc1b86f9b7a93526b4c4451
1 import blockcipher
2 import Crypto.Cipher.DES3
4 MODE_ECB = 1
5 MODE_CBC = 2
6 MODE_CFB = 3
7 MODE_OFB = 5
8 MODE_CTR = 6
10 def new(key,mode=blockcipher.MODE_ECB,IV=None):
11 return DES3(key,mode,IV)
13 class DES3(blockcipher.BlockCipher):
14 #need test vectors
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):
18 >>> import DES3
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'
30 """
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)
36 def _test():
37 import doctest
38 doctest.testmod()
40 if __name__ == "__main__":
41 _test()