FUNCTIONS

func GetRegexes() (*regexp.Regexp, *regexp.Regexp) GetRegexes delivers the Regex objects required to parse user input.

func ParseUserInput(inp string, rx *regexp.Regexp) string ParseUserInput checks the user input against the passed compiled regex.

TYPES

type Board struct { // Has unexported fields. } Board is a struct that holds settings of the given enigma board object.

func NewBoard() *Board NewBoard creates an enigma board with the default settings for rotors and a empty plugboard.

func NewBoardWithSettings(inp UserInput) *Board NewBoardWithSettings creates an enigma board with the settings passed in the inp parameter.

func (b *Board) Code(input string) string Code translates the input string using the enigma algorithm. It works for encoding and decoding as the algorithm is the same for both directions.

func (b *Board) SetPlugboard(inputString string) bool SetPlugboard forwards the inputString to the Plugboard itself, where it is parsed

func (b *Board) SetRotorPositions(rLeftPosition, rCenterPosition, rRightPosition int) SetRotorPositions - key settings - moves the rotors into the passed position.

func (b *Board) SetRotorSettings(rLeftSetting, rCenterSetting, rRightSetting int) SetRotorSettings - Ring Settings - sets the passed settings of the rotors.

func (b *Board) SetRotorTypes(rLeftRotor, rCenterRotor, rRightRotor int) SetRotorTypes - Sets the types of the rotors on the enigma board.

func (b *Board) SwapLetters(inputLetter string) string SwapLetters simulates the plugboards operation. It receives a letter as a string and gives the plugboard output for it. If this letter is not connected then it is returned

type Plugboard struct { // Has unexported fields. } Plugboard represents the plugboard available on chosen Enigma machines. This struct contains an array with letter pairs, that are swapped before and after the encoding happens.

func (p *Plugboard) IsPlugboardLetter(letter string) bool isPlugboardLetter checks if the passed letter is available on the plugboard.

func (p *Plugboard) PlugboardParseString(pairString string) bool PlugboardParseString parses a string in the form AB CD EF GH … with max 13 pairs. Each letter can only be used once.

type Rotor struct { // Has unexported fields. } Rotor describes the basic structure of a rotor inside a Enigma machine.

func (r *Rotor) ApplyRotorSettingToBase() string Like the byte-shift operation - shift the letters to the right in a circle

func (r *Rotor) GetRotorJump() map[int][]int GetRotorJump contains the rotor positions, at which the rotors will ‘kick’ the next rotor on the left side. The other rotor will increment its current position.

func (r *Rotor) GetRotorMap() map[int]string GetRotorMap returns the mapping of letters for rotors. It describes the internal wiring in dependency of the rotor type/number.

func (r *Rotor) SetRotorType(num int) SetRotorType sets the type (number) of the rotor. It also find the appropriate translation mapping and jump table.

type UserInput struct { Rotors string Reflector string KeySettings string RingSettings string Plugs string } UserInput is a struct for cache’ing the settings, that the user gave when configuring his enigma machine. Is used to create a board and then encode or decode his message.