Crypto.Cipher.ARC4, bust or me doing something wrong?
exarkun at divmod.com
Tue Sep 20 18:26:16 CEST 2005
On Tue, 20 Sep 2005 16:08:19 +0100, Michael Sparks <michaels at rd.bbc.co.uk> wrote:
>I suspect this is a bug with AMK's Crypto package from
>http://www.amk.ca/python/code/crypto , but want to
>check to see if I'm being dumb before posting a bug
>I'm looking at using this library and to familiarise myself writing
>small tests with each of the ciphers. When I hit Crypto.Cipher.ARC4 I've
>found that I can't get it to decode what it encodes. This might be a
>case of PEBKAC, but I'm trying the following:
>>>> from Crypto.Cipher import ARC4 as cipher
>>>> key = "........"
>>>> obj = cipher.new(key)
>>>> obj.encrypt("This is some random text")
>Clearly this decode doesn't match the encode. Me being dumb or bug?
>Any comments welcome :)
You need two ARC4 instances. Performing any operation alters the internal state (as it is a stream cipher), which is why your bytes did not come out intact.
>>> import Crypto.Cipher.ARC4 as ARC4
>>> o = ARC4.new('hello monkeys')
>>> p = ARC4.new('hello monkeys')
>>> p.decrypt(o.encrypt('super secret message of doom'))
'super secret message of doom'
More information about the Python-list