1 from blockcipher
import *
2 import Crypto
.Cipher
.CAST
4 def new(key
,mode
=MODE_ECB
,IV
=None,counter
=None,segment_size
=None):
5 """Create a new cipher object
7 CAST 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
15 segment_size = amount of bits to use from the keystream in each chain part
16 -> supported values: multiple of 8 between 8 and the blocksize
17 of the cipher (only per byte access possible), default is 8
18 -> only needed for CFB mode
24 >>> from CryptoPlus.Cipher import CAST
26 ECB example: http://www.rfc-editor.org/rfc/rfc2144.txt
30 >>> key = "0123456712345678234567893456789A".decode('hex')
31 >>> plaintext = "0123456789ABCDEF".decode('hex')
32 >>> cipher = CAST.new(key,CAST.MODE_ECB,)
33 >>> cipher.encrypt(plaintext).encode('hex')
37 >>> from CryptoPlus.Cipher import CAST
38 >>> key = "0123456712".decode('hex')
39 >>> plaintext = "0123456789ABCDEF".decode('hex')
40 >>> cipher = CAST.new(key,CAST.MODE_ECB,)
41 >>> cipher.encrypt(plaintext).encode('hex').upper()
44 return CAST(key
,mode
,IV
,counter
,segment_size
)
46 class CAST(BlockCipher
):
47 def __init__(self
,key
,mode
,IV
,counter
,segment_size
):
48 cipher_module
= Crypto
.Cipher
.CAST
.new
50 BlockCipher
.__init
__(self
,key
,mode
,IV
,counter
,cipher_module
,segment_size
)
56 if __name__
== "__main__":