enigma
enigma copied to clipboard
Use more Java features (OOP / enum), split Rotor class, rename 'ringSettings'
Firstly, I'd like to thank you for your videos and I was delighted to see you abord the infamous Enigma topic. Great topic!
I've tried to improve your code by using some OOP features of Java, as well as enums, while remaining "readable" for a non-Java user and keeping your code style intact.
Enumsare great to represent different static configurations, so I "extracted" them when I could:RotorTypeandReflectorfor example.RotorStaterepresents the state of the (3) rotors theEnigmais using: thetype(created from I to VIII), theringOffset(created from0to25), and the mutable fieldrotorPosition(mutating from0to25during the object lifecycle).- I mutualized code in the
Plugboardclass to compute both thewiringandunpluggedCharactersfield at once - I improved a bit the printing of the execution time because I was bored while the program was running 😁
- I renamed variables where I could see fit (coherence with the rest of the code, more detailed, etc)
- I removed unused imports on files I modified and removed a few dead code
- I fixed https://github.com/mikepound/enigma/issues/5
- I used
private/publicandfinalkeywords as much as I could to be explicit about variable visibility and mutability (it personnaly helps me a lot when reading a new code)