
Block ciphers and the data encryption st andard 207
sage: from Crypto.Cipher import DES
For ease of discussion, strings of 16 hexadecimal characters will be used
for plaintext, key and ciphertext. Suppose the plaintext is
0xAAAABBBBCCCCDDDD
and the key is
0x0123456789ABCDEF.
To perform an encryption, a new DES object must be instantiated with the
key, but first the key will need to be converted into bytes:
sage: k = ’0123456789ABCDEF’
sage: key = k.decode(’hex’)
To encrypt, the plaintext must also first be converted into bytes:
sage: plaintext = ’AAAABBBBCCCCDDDD’
sage: pl = plaintext.decode(’hex’)
Now create a new DES instance with the key, and use the encrypt ...