mode constants are only in blockcipher
[python-cryptoplus.git] / src / Cipher / IDEA.py
blobf53e1163396af7f2e408e35183f7bde84d611607
1 from blockcipher import *
2 try:
3 import Crypto.Cipher.IDEA
4 except ImportError:
5 print "Crypto.Cipher.IDEA isn't available. You're probably using the Debian pycrypto version. Install the original pycrypto for IDEA."
6 raise
8 def new(key,mode=MODE_ECB,IV=None,counter=None):
9 """Create a new cipher object
11 IDEA using pycrypto for algo and pycryptoplus for ciphermode
13 new(key,mode=MODE_ECB,IV=None,counter=None):
14 key = raw string containing the keys
15 mode = python_AES.MODE_ECB/CBC/CFB/OFB/CTR/CMAC, default is ECB
16 IV = IV as a raw string
17 -> only needed for CBC mode
18 counter = counter object (CryptoPlus.Util.util.Counter)
19 -> only needed for CTR mode
21 https://www.cosic.esat.kuleuven.be/nessie/testvectors/
22 -----------------------------------------
23 >>> from CryptoPlus.Cipher import IDEA
24 >>> key = "2BD6459F82C5B300952C49104881FF48".decode('hex')
25 >>> plaintext = "F129A6601EF62A47".decode('hex')
26 >>> cipher = IDEA.new(key,IDEA.MODE_ECB,)
27 >>> cipher.encrypt(plaintext).encode('hex').upper()
28 'EA024714AD5C4D84'
29 """
30 return IDEA(key,mode,IV,counter)
32 class IDEA(BlockCipher):
33 def __init__(self,key,mode,IV,counter):
34 self.cipher = Crypto.Cipher.IDEA.new(key)
35 self.blocksize = Crypto.Cipher.IDEA.block_size
36 BlockCipher.__init__(self,key,mode,IV,counter)
38 def _test():
39 import doctest
40 doctest.testmod()
42 if __name__ == "__main__":
43 _test()