IV default is an "all zero" string by default
[python-cryptoplus.git] / src / CryptoPlus / Cipher / DES.py
blob033f6852359f5b8ecf9f48e633ee79fe3d6fb76d
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 key = raw string containing the keys
10 mode = python_AES.MODE_ECB/CBC/CFB/OFB/CTR/CMAC, default is ECB
11 IV = IV as a raw string, default is "all zero" IV
12 -> only needed for CBC mode
13 counter = counter object (CryptoPlus.Util.util.Counter)
14 -> only needed for CTR mode
16 EXAMPLES:
17 **********
18 IMPORTING:
19 -----------
20 >>> from CryptoPlus.Cipher import DES
22 EXAMPLE (test vectors from NESSIE):
23 -----------------------------------
25 >>> cipher = DES.new(('7CA110454A1A6E57').decode('hex'))
26 >>> ciphertext = cipher.encrypt(('01A1D6D039776742').decode('hex'))
27 >>> (ciphertext).encode('hex')
28 '690f5b0d9a26939b'
29 >>> plaintext = cipher.decrypt(ciphertext)
30 >>> (plaintext).encode('hex')
31 '01a1d6d039776742'
33 """
34 return DES(key,mode,IV,counter)
36 class DES(BlockCipher):
37 def __init__(self,key,mode,IV,counter):
38 cipher_module = Crypto.Cipher.DES.new
39 self.blocksize = 8
40 BlockCipher.__init__(self,key,mode,IV,counter,cipher_module)
42 def _test():
43 import doctest
44 doctest.testmod()
46 if __name__ == "__main__":
47 _test()