1 from blockcipher
import *
4 def new(key
,mode
=MODE_ECB
,IV
=None,counter
=None,segment_size
=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, default is "all zero" IV
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
18 segment_size = amount of bits to use from the keystream in each chain part
19 -> supported values: multiple of 8 between 8 and the blocksize
20 of the cipher (only per byte access possible), default is 8
21 -> only needed for CFB mode
27 >>> from CryptoPlus.Cipher import python_DES
29 EXAMPLE (test vectors from NESSIE):
30 -----------------------------------
31 >>> cipher = python_DES.new(('7CA110454A1A6E57').decode('hex'))
32 >>> ciphertext = cipher.encrypt(('01A1D6D039776742').decode('hex'))
33 >>> (ciphertext).encode('hex')
35 >>> plaintext = cipher.decrypt(ciphertext)
36 >>> (plaintext).encode('hex')
39 return python_DES(key
,mode
,IV
,counter
,segment_size
)
41 class python_DES(BlockCipher
):
42 key_error_message
= ("Key should be 64 bits")
44 def __init__(self
,key
,mode
,IV
,counter
,segment_size
):
45 cipher_module
= pyDes
.des
47 BlockCipher
.__init
__(self
,key
,mode
,IV
,counter
,cipher_module
,segment_size
)
49 def keylen_valid(self
,key
):
56 if __name__
== "__main__":