enigma icon indicating copy to clipboard operation
enigma copied to clipboard

Use more Java features (OOP / enum), split Rotor class, rename 'ringSettings'

Open NinoDLC opened this issue 3 years ago • 0 comments

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.

  • Enums are great to represent different static configurations, so I "extracted" them when I could: RotorType and Reflector for example.
  • RotorState represents the state of the (3) rotors the Enigma is using: the type (created from I to VIII), the ringOffset (created from 0 to 25), and the mutable field rotorPosition (mutating from 0 to 25 during the object lifecycle).
  • I mutualized code in the Plugboard class to compute both the wiring and unpluggedCharacters field 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/public and final keywords as much as I could to be explicit about variable visibility and mutability (it personnaly helps me a lot when reading a new code)

NinoDLC avatar May 29 '22 19:05 NinoDLC