Nov-19-2017, 10:06 PM
Completely rewrote rotor class, it's not tested, but code is on github, and here:
import string import random class Rotor: def __init__(self, starting_index=0, output_encoding=None, notch_index=None): ''' Initialization :param starting_index: optional initial starting index ''' self.current_index = 0 self.input_encoding = list(string.ascii_uppercase) if output_string: self.output_encoding = output_encoding else: self.output_encoding = random.shuffle(list(string.ascii_uppercase)) self.index = starting_index self.minmax = [0, 25] self.notch_index = notch_index self.advance_next_rotor = False def click(self): ''' rotate rotor 1 click, if notch at click set advance flag :return: ''' self.advance_next_rotor = False gotnotch = None self.current_index += 1 if self.current_index > self.minmax[1]: self.current_index = self.minmax[0] self.advance_next_rotor = self.notch_index and self.notch_index == self.current_index def get_next_char(self, char_in): ''' Advance Rotor and return encoded character and advance flag :param char_in: :return: ''' self.click() charidx = self.input_encoding.index(char_in) return self.output_encoding[charidx], self.advance_next_rotor def show_encoding(self): ''' return encoding info :return: input encoding, output encoding, notch index ''' return self.input_encoding, self.output_encoding, self.notch_index def test_rotor(self): pass if __name__ == '__main__': rot = Rotor() rot.test_rotor()