artemis-beta/enigma

TypeError when runing enigma_test

Closed this issue · 2 comments

$ python enigma_test.py

===========================================

  WELCOME TO THE PYTHON ENIGMA 3 ENCODER
                  v0.1.0 (BETA)
          
           Kristian Zarebski

===========================================
Type 'q' or 'quit' to exit.
              

INPUT: hello
Traceback (most recent call last):
  File "enigma_test.py", line 30, in <module>
    print(enigma_m3.type_phrase(inp))
  File "/home/maxnoe/Projects/enigma/enigma/__init__.py", line 127, in type_phrase
    out_str += self.type_letter(letter)
TypeError: Can't convert 'NoneType' object to str implicitly

@maxnoe Thanks for this, I noticed this yesterday trying to work out why exactly this happens as it only seems to be some rotor/letter combinations that cause the issue.

Hey @maxnoe so good news after being so busy I was not able to look into this for quite a while. The good news is after adding a few more printed statements I have tracked down the issue to the usage of the classes as opposed to the classes themselves. The issue is that the wiring dictionary I have used (where I set A-Z to have indexes 0-25) has duplicates! So some numbers return None.

ERROR: Could not find key which returns alphabet index 9 in wiring dictionary:
[4, 10, 12, 5, 11, 6, 3, 16, 21, 25, 13, 19, 15, 22, 24, 7, 23, 20, 18, 15, 0, 8, 1, 17, 2, 19]
Duplicates Found:
{19, 15}

I will apply the fix and add the above check to the code so it is detected before returning None