As an exercise for me I want to write an Enigma machine which can be used as an emulator for the many Enigma devices known.
The Enigma machine used to have “Rotors”, which normally are represented in code as a list
of 26 uppercase letters in an array/slice. There are a lot of different rotor setting with different sequences of characters.
I want to implement a function, which accepts the name of a certain rotor and returns its configuration as a pointer to a slice.
My goals is:
- not to use global variables
- not to initialize all rotors each time the above mentioned function get called
- to minimize re-initialize of data
- make it easy to modify
My idea was to use static const u8 slices - one for each rotor and then initialize a hashmap with
the names of the rotors as keys and slice.ptr as its corresponding values.
But how can I initialize a static hashmap with all those key/value-pairs?
And all these static stuff looks not very “beautiful” to me.
As an example:
This is how such an rotor setting looks like (data source: Wikipedia):
static const rotor_ic :u8 = “DMTWSILRUYQNKFEJCAZBPGXOHV”;
…but I am sure, there are more elegant ways to implement such a functionality in a far more ziglike fashion…
Any ideas for improvements?