Crypto.Cipher.ARC4, bust or me doing something wrong?
Michael J. Fromberger
Michael.J.Fromberger at Clothing.Dartmouth.EDU
Wed Sep 21 00:33:50 CEST 2005
In article <dgpbuu$8eb$1 at nntp0.reith.bbc.co.uk>,
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")
> >>> X=_
> >>> X
> >>> obj.decrypt(X)
> Clearly this decode doesn't match the encode. Me being dumb or bug?
> Any comments welcome :)
Since ARC4 is a stream cipher, the keystream changes over time -- with
ARC4, after each character enciphered. To decrypt successfully, you
need to make sure the decrypting keystream exactly matches the
In your example, you used a different keystream to decrypt than you used
to encrypt -- in this case, a little further downstream of the original
Contrast your experience above with the following transcript:
>>> from Crypto.Cipher import ARC4 as cipher
>>> enc = cipher.new("abcdefgh")
>>> dec = cipher.new("abcdefgh")
>>> x = enc.encrypt("This is some random text")
>>> y = dec.decrypt(x)
'This is some random text'
I hope this helps clear up your confusion.
Michael J. Fromberger | Lecturer, Dept. of Computer Science
http://www.dartmouth.edu/~sting/ | Dartmouth College, Hanover, NH, USA
More information about the Python-list