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 -----------------------------------
20 >>> from binascii import hexlify, unhexlify
21 >>> cipher = DES.new(unhexlify('7CA110454A1A6E57'))
22 >>> ciphertext = cipher.encrypt(unhexlify('01A1D6D039776742'))
23 >>> hexlify(ciphertext)
25 >>> plaintext = cipher.decrypt(ciphertext)
26 >>> hexlify(plaintext)
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
)
42 if __name__
== "__main__":