1 from blockcipher
import *
4 def new(key
,mode
=MODE_ECB
,IV
=None,counter
=None):
5 """Create a new cipher object
7 wrapper for pure python implementation pyDes.py
9 key = raw string containing the key
10 mode = python_DES.MODE_ECB/CBC/CFB/OFB/CTR/CMAC, default is ECB
11 -> for every mode, except ECB and CTR, it is important to construct a seperate cipher for encryption and decryption
12 IV = IV as a raw string
13 -> needed for CBC, CFB and OFB mode
14 counter = counter object (CryptoPlus.Util.util.Counter)
15 -> only needed for CTR mode
16 -> use a seperate counter object for the cipher and decipher: the counter is updated directly, not a copy
17 see CTR example further on in the docstring
23 >>> from CryptoPlus.Cipher import python_DES
25 EXAMPLE (test vectors from NESSIE):
26 -----------------------------------
27 >>> cipher = python_DES.new(('7CA110454A1A6E57').decode('hex'))
28 >>> ciphertext = cipher.encrypt(('01A1D6D039776742').decode('hex'))
29 >>> (ciphertext).encode('hex')
31 >>> plaintext = cipher.decrypt(ciphertext)
32 >>> (plaintext).encode('hex')
35 return python_DES(key
,mode
,IV
,counter
)
37 class python_DES(BlockCipher
):
38 key_error_message
= ("Key should be 64 bits")
40 def __init__(self
,key
,mode
,IV
,counter
):
41 cipher_module
= pyDes
.des
43 BlockCipher
.__init
__(self
,key
,mode
,IV
,counter
,cipher_module
)
45 def keylen_valid(self
,key
):
52 if __name__
== "__main__":