Class: Enigma::Plugboard

Inherits:
Object
  • Object
show all
Defined in:
lib/enigma/plugboard.rb

Overview

The engima plugboard is used to swap letters before and after the rotors execute. It provided an additional layer of security increasing the permutations.

Usage:

reflector = Enigma::Reflector.new
machine.reflect('A') # 'B'
machine.reflect('B') # 'A'
...

Instance Method Summary collapse

Constructor Details

#initializePlugboard

Returns a new instance of Plugboard.


16
17
18
# File 'lib/enigma/plugboard.rb', line 16

def initialize
  @mappings = {}
end

Instance Method Details

#plug(character_a, character_b) ⇒ Object


20
21
22
23
# File 'lib/enigma/plugboard.rb', line 20

def plug(character_a, character_b)
  @mappings[character_a] = character_b
  @mappings[character_b] = character_a
end

#swap(character) ⇒ Object


25
26
27
# File 'lib/enigma/plugboard.rb', line 25

def swap(character)
  @mappings[character] || character
end