[pycrypto] ARC4 problems?
Parke
parke.nexus at gmail.com
Fri Nov 22 18:01:12 PST 2013
On Thu, Nov 21, 2013 at 1:58 AM, Dave Pawson <dave.pawson at gmail.com> wrote:
> Using Python 3
>
> def test_ARC4_2(self):
> key = b'A long and confidential key'
> msg =b'My secret message'
> nonce = b'Another secret'#Crypto.Random.new().read(16)
> tempkey=SHA.new(key + nonce).digest()
> cipher = ARC4.new(tempkey)
> ciphertext = cipher.encrypt(msg)
> plain = cipher.decrypt(ciphertext)
> print(plain)
>
> The print is showing
> b'\x06\xd6\x96\xe7BEF\xe2\x11\xae\xff\xa5"3nJ1'
> which str() won't convert to a string?
> An ecryption problem or encoding?
> Am I doing something wrong please?
> (just trying to get my head round each of the classes)
In Python 3, strings are Unicode, so str() probably needs to know
which encoding to use. Your plaintext msg is bytes (not str). Why do
you (think you) want/need str?
Also, nonces do not need to be secret, just unique (per key).
You may need to create a new/fresh ARC4 instance for the decryption.
ARC4 is a stream cipher, and you reset it by installing the key+nonce.
Block ciphers in ECB and CTR mode do not need to be reset between
encryption and decryption. But most other ciphers/modes do.
-Parke
More information about the pycrypto
mailing list