1 from blockcipher
import *
2 import Crypto
.Cipher
.ARC2
4 from pkg_resources
import parse_version
6 def new(key
,mode
=MODE_ECB
,IV
=None,counter
=None,effective_keylen
=None,segment_size
=None):
7 """Create a new cipher object
9 ARC2 using pycrypto for algo and pycryptoplus for ciphermode
11 key = raw string containing the keys
12 mode = python_AES.MODE_ECB/CBC/CFB/OFB/CTR/CMAC, default is ECB
13 IV = IV as a raw string, default is "all zero" IV
14 -> only needed for CBC mode
15 counter = counter object (CryptoPlus.Util.util.Counter)
16 -> only needed for CTR mode
17 effective_keylen = how much bits to effectively use from the supplied key
18 -> will only be used when the pycrypto version on your system is >2.0.1
24 >>> from CryptoPlus.Cipher import ARC2
26 http://www.ietf.org/rfc/rfc2268.txt
27 Doctest will fail when using pycrypto 2.0.1 and older
28 ------------------------------------
29 >>> key = "0000000000000000".decode('hex')
30 >>> plaintext = "0000000000000000".decode('hex')
32 >>> cipher = ARC2.new(key,ARC2.MODE_ECB,effective_keylen=ek)
33 >>> cipher.encrypt(plaintext).encode('hex')
36 return ARC2(key
,mode
,IV
,counter
,effective_keylen
,segment_size
)
38 class ARC2(BlockCipher
):
39 def __init__(self
,key
,mode
,IV
,counter
,effective_keylen
,segment_size
):
40 # pycrypto versions newer than 2.0.1 will have support for "effective_keylen"
41 if parse_version(Crypto
.__version
__) <= parse_version("2.0.1"):
42 cipher_module
= Crypto
.Cipher
.ARC2
.new
45 cipher_module
= Crypto
.Cipher
.ARC2
.new
46 args
= {'effective_keylen':effective_keylen
}
48 BlockCipher
.__init
__(self
,key
,mode
,IV
,counter
,cipher_module
,segment_size
,args
)
54 if __name__
== "__main__":