I’m afraid that just an array of chars is not enough for describing a rotor of Enigma cipher machine, because
By itself, a rotor performs only a very simple type of encryption, a simple substitution cipher. For example, the pin corresponding to the letter E might be wired to the contact for letter T on the opposite face, and so on.
So you need some mapping from right side contacts to left side contacts.
Quick improvisation:
const EnigmaDevice = struct {
const Letter = struct {
char: u8,
plate: u5, // left side contact
pin: u5, // right side contact
};
const Rotor = struct {
letters: [26]Letter,
position: u5,
}
...
};
There totally are! But I think their problem here is that they’re trying to initialize a mutable slice of non-mutable string slices from what resembles an array literal (i.e. anonymous) which is implicitly non-mutable.
But, as you remarked, this might not be enough to tackle their problem anyway. If you want them mutable, make it an array of string slices, but at that point you need to know the size beforehand (or pass it in as a generic type parameter or similar).