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):
7 """Create a new cipher object
9 ARC2 using pycrypto for algo and pycryptoplus for ciphermode
11 new(key,mode=MODE_ECB,IV=None,counter=None,effective_keylen=None):
12 key = raw string containing the keys
13 mode = python_AES.MODE_ECB/CBC/CFB/OFB/CTR/CMAC, default is ECB
14 IV = IV as a raw string
15 -> only needed for CBC mode
16 counter = counter object (CryptoPlus.Util.util.Counter)
17 -> only needed for CTR mode
18 effective_keylen = how much bits to effectively use from the supplied key
19 -> will only be used when the pycrypto version on your system is >2.0.1
21 http://www.ietf.org/rfc/rfc2268.txt
22 Doctest will fail when using pycrypto 2.0.1 and older
23 ------------------------------------
24 >>> from CryptoPlus.Cipher import ARC2
25 >>> key = "0000000000000000".decode('hex')
26 >>> plaintext = "0000000000000000".decode('hex')
28 >>> cipher = ARC2.new(key,ARC2.MODE_ECB,effective_keylen=ek)
29 >>> cipher.encrypt(plaintext).encode('hex')
32 return ARC2(key
,mode
,IV
,counter
,effective_keylen
)
34 class ARC2(BlockCipher
):
35 def __init__(self
,key
,mode
,IV
,counter
,effective_keylen
):
36 # pycrypto versions newer than 2.0.1 will have support for "effective_keylen"
37 if parse_version(Crypto
.__version
__) <= parse_version("2.0.1"):
38 self
.cipher
= Crypto
.Cipher
.ARC2
.new(key
)
40 self
.cipher
= Crypto
.Cipher
.ARC2
.new(key
,effective_keylen
=effective_keylen
)
41 self
.blocksize
= Crypto
.Cipher
.ARC2
.block_size
42 BlockCipher
.__init
__(self
,key
,mode
,IV
,counter
)
48 if __name__
== "__main__":