The StdProcedure class encapsulates the encrypting and decrypting procedures outlined in References. In particular, see references [5] and [7]. This class takes care of the high level details of inserting various message indicators into an encrypted message, and stripping them off during decrypt. These message indicators tell the recipient what key list and initial key wheel settings to use when configuring their M-209 for decrypt.
Parameters: |
|
---|
Before an encrypt() operation can be performed, a valid key list must be installed, either during procedure object construction, or by the set_key_list() method.
Decrypt operations are performed in a 3-step process.
StdProcedure objects have the following methods:
- set_key_list(key_list)¶
Establishes the KeyList to be used for future encrypt() and decrypt() operations
Parameters: key_list – the new KeyList to use
- encrypt(plaintext[, spaces=True[, ext_msg_ind=None[, sys_ind=None]]])
Encrypts a plaintext message using the installed KeyList and by following the standard procedure. The encrypted text with the required message indicators are returned as a string.
Parameters:
- plaintext – the input string to be encrypted
- spaces – if True, space characters in the input plaintext are allowed and will be replaced with Z characters before encrypting
- ext_msg_ind – this is the external message indicator, which, if supplied, must be a valid 6-letter string of key wheel settings. If not supplied, one will be generated randomly.
- sys_ind – this is the system indicator, which must be a string of length 1 in the range A - Z, inclusive. If None, one is chosen at random.
Returns: the encrypted text with the required message indicators
Raises ProcedureError: if the procedure does not have a KeyList or the input indicators are invalid
- set_decrypt_message(msg)¶
Prepare to decrypt the supplied message.
Parameters: msg – the messsage to decrypt. The message can be grouped into 5-letter groups separated by spaces or accepted without spaces. Returns: a DecryptParams named tuple to the caller (see below) The DecryptParams named tuple has the following attributes:
- sys_ind - the system indicator
- ext_msg_ind - the external message indicator
- key_list_ind - the key list indicator
- ciphertext - the cipher text with all indicators removed
The caller should ensure the procedure instance has the required KeyList before calling decrypt(). The key_list_ind attribute of the returned DecryptParams named tuple identifies the key list that should be installed with set_key_list().
- decrypt()
Decrypt the message set in a previous set_decrypt_message() call. The resulting plaintext is returned as a string.
Returns: the decrypted plaintext as a string Raises ProcedureError: if the procedure instance has not been previously configured with the required KeyList via set_key_list()
Here is a simple interactive example of performing an encrypt operation. Here we choose a random key list from our key list file, and use random indicators:
>>> from m209.keylist.config import read_key_list
>>> from m209.procedure import StdProcedure
>>>
>>> key_list = read_key_list('m209keys.cfg')
>>> proc = StdProcedure(key_list=key_list)
>>> ct = proc.encrypt('ORDER THE PIZZA AT TWELVE HUNDRED HOURS')
>>> ct
'YYGBM ENNHT VBMTJ PEEFV JWLUU PAFTS VOHEA QEPEQ OKVUA XDAUX YYGBM ENNHT'
>>>
The first and last two groups of this message contain the indicators. Here we can see the system indicator was Y, the external message indicator is GBMENN, and the key list indicator is HT.
An example session for decrypting the above message might look like:
>>> proc = StdProcedure()
>>> ct = 'YYGBM ENNHT VBMTJ PEEFV JWLUU PAFTS VOHEA QEPEQ OKVUA XDAUX YYGBM ENNHT'
>>> params = proc.set_decrypt_message(ct)
>>> params
DecryptParams(sys_ind='Y', ext_msg_ind='GBMENN', key_list_ind='HT', ciphertext='VBMTJ PEEFV JWLUU PAFTS VOHEA QEPEQ OKVUA XDAUX')
>>> key_list = read_key_list('m209keys.cfg', params.key_list_ind)
>>> proc.set_key_list(key_list)
>>> pt = proc.decrypt()
>>> pt
'ORDER THE PI A AT TWELVE HUNDRED HOURS '
>>>