-
Notifications
You must be signed in to change notification settings - Fork 15
/
reflector.go
33 lines (29 loc) · 869 Bytes
/
reflector.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package enigma
// Reflector is used to reverse a signal inside the Enigma: the current
// goes from the keys through the rotors to the reflector, then it is
// reversed and goes through the rotors again in the opposite direction.
type Reflector struct {
ID string
Sequence [26]int
}
// NewReflector is a constuctor, taking a reflector mapping and
// its ID (name).
func NewReflector(mapping string, id string) *Reflector {
var seq [26]int
for i, value := range mapping {
seq[i] = CharToIndex(byte(value))
}
return &Reflector{id, seq}
}
// Reflectors is a simple list of reflector pointers.
type Reflectors []Reflector
// GetByID takes a "name" of the reflector (e.g. "B") and returns the
// Reflector pointer.
func (refs *Reflectors) GetByID(id string) *Reflector {
for _, ref := range *refs {
if ref.ID == id {
return &ref
}
}
return nil
}