[pycrypto] DES3 problem

Dave Pawson dave.pawson at gmail.com
Fri Nov 29 07:49:07 PST 2013


On 29 November 2013 15:16, Legrandin <helderijs at gmail.com> wrote:

> The DES3 example you are looking for is actually here:
>
> https://www.dlitz.net/software/pycrypto/api/current/Crypto.Cipher.DES-module.html


I can't get that working.

Request please?
Assuming I'm not unusual in wanting to both encrypt and then decrypt.
It would be very helpful to show the decrypt after the encrypt?
the oddities I'm finding,
1. Why is it sometimes (I don't know why) shown creating two ciphers,
one for encrypt, one for decrypt.
2. The use of a nonce (as per above)
Is it normal to decrypt using

ciphertext=iv + ciphere.encrypt(plaintext)
plain = cipherd.decrypt(ciphertext[16:])

Using the example....

>>> from Crypto.Cipher import DES3
>>> from Crypto import Random
>>> key = b'Sixteen byte key'
>>> iv = Random.new().read(DES3.block_size)
>>> cipher = DES3.new(key, DES3.MODE_OFB, iv)
>>> plaintext = b'sona si latine loqueris '
>>> msg = iv + cipher.encrypt(plaintext)
>>> p = cipher.decrypt(msg[16:])
>>> print(p)
b'\xc0/)~\xc1\xa4\xb0\xb3\x0c\x92y_\x9a\xaa\xe3\xa0'

Any ideas please?


TiA






-- 
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.
http://www.dpawson.co.uk


More information about the pycrypto mailing list