[ pycrypto-Bugs-1057423 ] Stream chiphers don't work

"SourceForge.net" <[email protected]> Mon, 09 May 2005 07:10:05 -0700
Newsgroups gmane.comp.python.cryptography.cvs
Message-ID <[email protected]>
Bugs item #1057423, was opened at 2004-10-30 14:16
Message generated for change (Comment added) made by akuchling
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=120937&aid=1057423&group_id=20937

Category: None
Group: None
>Status: Closed
>Resolution: Wont Fix
Priority: 5
Submitted By: Erik Andersén (erik_andersen)
>Assigned to: A.M. Kuchling (akuchling)
Summary: Stream chiphers don't work

Initial Comment:
The decrypted ciphertext is not equal to the 
plaintext with stream ciphers.

File testcrypto:

import Crypto
from Crypto.Cipher import ARC4, XOR, DES

import unittest, random


def randString(n):
    """returns a random string of length n"""
    return ''.join([chr(random.randrange(0,256)) for 
dummy in xrange(n)])

n_tests = 100

class StreamCipherTest(unittest.TestCase):
    def testARC4(self):
        for dummy in range(n_tests):
            obj = ARC4.new('jaudjdj')
            s = randString(10)
            self.assertEqual(obj.decrypt(obj.encrypt(s)), 
s)
    def testXOR(self):
        for dummy in range(n_tests):
            obj = XOR.new('jaudjdj')
            s = randString(10)
            self.assertEqual(obj.decrypt(obj.encrypt(s)), 
s)
    def testDES(self):
        for dummy in range(n_tests):
            obj = DES.new('jaudjdji', DES.MODE_ECB)
            s = randString(16)
            self.assertEqual(obj.decrypt(obj.encrypt(s)), 
s)

if __name__ == '__main__':
    print Crypto.__version__
    unittest.main()


-----------------Output ------------

PythonWin 2.3.4 (#53, May 25 2004, 21:17:02) 
[MSC v.1200 32 bit (Intel)] on win32.
Portions Copyright 1994-2004 Mark Hammond 
([email protected]) - see 'Help/About 
PythonWin' for further copyright information.
>>> 2.0
F.F
====================================
==================================
FAIL: testARC4 (__main__.StreamCipherTest)
------------------------------------------------------------------
----
Traceback (most recent call last):
  File "C:\erik\python\testcrypto.py", line 18, in 
testARC4
    self.assertEqual(obj.decrypt(obj.encrypt(s)), s)
  File "C:\Python23\lib\unittest.py", line 302, in 
failUnlessEqual
    raise self.failureException, AssertionError: '@i$^\x1a\xccdC\x8b\xa0' != 
'kS\xd5{\xa3\xe2\xec\x1a(~'

====================================
==================================
FAIL: testXOR (__main__.StreamCipherTest)
------------------------------------------------------------------
----
Traceback (most recent call last):
  File "C:\erik\python\testcrypto.py", line 23, in 
testXOR
    self.assertEqual(obj.decrypt(obj.encrypt(s)), s)
  File "C:\Python23\lib\unittest.py", line 302, in 
failUnlessEqual
    raise self.failureException, AssertionError: '\t\xef\x0b\xf4h\xeb\x89\xa2\xaf^' !
= '\x07\xe4\x1a\xfah\xee\x96\xac\xa4O'

------------------------------------------------------------------
----
Ran 3 tests in 0.047s

FAILED (failures=2)



----------------------------------------------------------------------

>Comment By: A.M. Kuchling (akuchling)
Date: 2005-05-09 10:10

Message:
Logged In: YES 
user_id=11375

Not a bug: stream ciphers are stateful, so you can't use the
same object for both encryption and decryption.   Create two
different objects instead.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=120937&aid=1057423&group_id=20937


-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.
Get your fingers limbered up and give it your best shot. 4 great events, 4
opportunities to win big! Highest score wins.NEC IT Guy Games. Play to
win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=20