1 from blockcipher
import *
2 import Crypto
.Cipher
.CAST
4 def new(key
,mode
=MODE_ECB
,IV
=None,counter
=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
12 -> only needed for CBC mode
13 counter = counter object (CryptoPlus.Util.util.Counter)
14 -> only needed for CTR mode
20 >>> from CryptoPlus.Cipher import CAST
22 ECB example: http://www.rfc-editor.org/rfc/rfc2144.txt
26 >>> key = "0123456712345678234567893456789A".decode('hex')
27 >>> plaintext = "0123456789ABCDEF".decode('hex')
28 >>> cipher = CAST.new(key,CAST.MODE_ECB,)
29 >>> cipher.encrypt(plaintext).encode('hex')
33 >>> from CryptoPlus.Cipher import CAST
34 >>> key = "0123456712".decode('hex')
35 >>> plaintext = "0123456789ABCDEF".decode('hex')
36 >>> cipher = CAST.new(key,CAST.MODE_ECB,)
37 >>> cipher.encrypt(plaintext).encode('hex').upper()
40 return CAST(key
,mode
,IV
,counter
)
42 class CAST(BlockCipher
):
43 def __init__(self
,key
,mode
,IV
,counter
):
44 cipher_module
= Crypto
.Cipher
.CAST
.new
46 BlockCipher
.__init
__(self
,key
,mode
,IV
,counter
,cipher_module
)
52 if __name__
== "__main__":