mode constants are only in blockcipher
[python-cryptoplus.git] / src / Cipher / DES.py
blob22d4103dcf28fc329cf49010d66603eabe3bf5c8
1 from blockcipher import *
2 import Crypto.Cipher.DES
4 def new(key,mode=MODE_ECB,IV=None,counter=None):
5 """Create a new cipher object
7 DES using pycrypto for algo and pycryptoplus for ciphermode
9 new(key,mode=MODE_ECB,IV=None,counter=None):
10 key = raw string containing the keys
11 mode = python_AES.MODE_ECB/CBC/CFB/OFB/CTR/CMAC, default is ECB
12 IV = IV as a raw string
13 -> only needed for CBC mode
14 counter = counter object (CryptoPlus.Util.util.Counter)
15 -> only needed for CTR mode
17 EXAMPLE (test vectors from NESSIE):
18 -----------------------------------
19 >>> import DES
20 >>> from binascii import hexlify, unhexlify
21 >>> cipher = DES.new(unhexlify('7CA110454A1A6E57'))
22 >>> ciphertext = cipher.encrypt(unhexlify('01A1D6D039776742'))
23 >>> hexlify(ciphertext)
24 '690f5b0d9a26939b'
25 >>> plaintext = cipher.decrypt(ciphertext)
26 >>> hexlify(plaintext)
27 '01a1d6d039776742'
29 """
30 return DES(key,mode,IV,counter)
32 class DES(BlockCipher):
33 def __init__(self,key,mode,IV,counter):
34 self.cipher = Crypto.Cipher.DES.new(key)
35 self.blocksize = Crypto.Cipher.DES.block_size
36 BlockCipher.__init__(self,key,mode,IV,counter)
38 def _test():
39 import doctest
40 doctest.testmod()
42 if __name__ == "__main__":
43 _test()