# HG changeset patch # User Brian Neal # Date 1392582684 21600 # Node ID 9c90ca37c023bd28cc7b72d3b3c4c7a40da30632 # Parent 6408a3f67d25a60abff3be28bae3eb3fbb75070d No need to create a new set to handle a garble on encrypt. diff -r 6408a3f67d25 -r 9c90ca37c023 purple/machine.py --- a/purple/machine.py Sun Feb 16 14:30:57 2014 -0600 +++ b/purple/machine.py Sun Feb 16 14:31:24 2014 -0600 @@ -1,4 +1,4 @@ -# Copyright (C) 2013 by Brian Neal. +# Copyright (C) 2013 - 2014 by Brian Neal. # This file is part of purple, the PURPLE (Cipher Machine 97) simulation. # purple is released under the MIT License (see LICENSE.txt). @@ -30,7 +30,6 @@ """ VALID_KEYS = set(string.ascii_uppercase) - VALID_DECRYPT_KEYS = set(string.ascii_uppercase + '-') STRAIGHT_PLUGBOARD = 'AEIOUYBCDFGHJKLMNPQRSTVWXZ' def __init__(self, switches_pos=None, fast_switch=1, middle_switch=2, @@ -186,8 +185,6 @@ """ plaintext = [] for i, c in enumerate(ciphertext): - if c not in self.VALID_DECRYPT_KEYS: - raise Purple97Error("invalid input '{}' to decrypt".format(c)) # Process a garble: if c == '-': @@ -195,6 +192,9 @@ self.step() continue + if c not in self.VALID_KEYS: + raise Purple97Error("invalid input '{}' to decrypt".format(c)) + n = self.plugboard[c] if n < 6: