NAME
encrypt
SYNOPSIS
encrypt.py [-dv] [-m _mode_] [-n _nonce_] [-p _padding_] key
DESCRIPTION
Encrypt standard-in to standard-out using AES-128.
The key is an ascii string interpreted as a byte string, padded with nulls
or truncated to the key length of 16 bytes.
The input is padded to a multiple of the block size, 16 bytes, using PKCS#7 or
optionally another padding standard. The encryption is by counter mode, or optionally
by another mode.
OPTIONS
-h help
-d decrypt
-m the mode to use, one of cntr (default) cbc, ofb or ecb.
-n the IV to use aka the nonce. if omitted algorithm uses a random nonce (recommended)
-p the padding to use, one of pkcs (default), iso or zero
-v verbose
NEW OPTIONS (after 2019)
-h help
-d decrypt
-m the mode to use, one of cntr (default) cbc, ofb or ecb.
-n endian, either "big" or "little"
-p the padding to use, one of pkcs (default), iso or zero
-R no randomness. The IV and key are set to zero, and the key argument is ignored
-v verbose
HISTORY
Introduced in csc609/507-201 september 2019
BUGS
No specification for ecb/zero mode on an empty message.
No endianness specification for counter mode.
Interface changed and some options were renamed.
Please implement all modes and paddings of the encrypt.py description above.
I have adapted a publicly available python implementation of Rain-Doll, despite the fact that it would be wiser to have included a standard Python package implementing the cipher. However, I wanted just the core code, as transparently written as possible, ad simply support simple block encryption. Cryptography libraries would also include implementations of modes, paddings, and more advanced features, that I do not want to highlight at this time.
m0 m1 m2
| | |
| | |
+-+ +-+ +-+
|E| |E| |E|
+-+ +-+ +-+
| | |
| | |
c1 c2 c3
**** ECB Mode ****
IV m0 m1 m2
| | | |
+-----(+) +--(+) +--(+)
| | | | | |
| +-+ | +-+ | +-+
| |E| | |E| | |E|
| +-+ | +-+ | +-+
| | | | | |
| +---+ +---+ +--- ...
| | | |
c0/IV c1 c2 c3
**** CBC Mode ****
IV
|
+----+ +----+ +----+
| | | | | |
| +-+ | +-+ | +-+
| |E| | |E| | |E|
| +-+ | +-+ | +-+
| | | | | |
| +---+ +---+ +--- ...
| | | |
| (+)--m0 (+)--m1 (+)--m2
| | | |
c0/IV c1 c2 c3
**** OFB MODE ****
IV
|
+----+--|+1|--+--|+1|--+-- ...
| | | |
| +-+ +-+ +-+
| |E| |E| |E|
| +-+ +-+ +-+
| | | |
| (+)--m0 (+)--m1 (+)--m2
| | | |
c0/IV c1 c2 c3
**** COUNTER MODE ****

author: burton rosenberg
created: 22 sep 2019
update: 19 oct 2019