Class: EnigmaMachine::Plugboard
- Inherits:
-
Object
- Object
- EnigmaMachine::Plugboard
- Defined in:
- lib/enigma_machine/plugboard.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#initialize(mapping_pairs, rotor) ⇒ Plugboard
constructor
Construct a new plugboard.
-
#substitute(letter) ⇒ String
Substitutes a letter according the configured plug pairs.
-
#translate(letter) ⇒ String
Translate a letter.
Constructor Details
Instance Method Details
#substitute(letter) ⇒ String
Substitutes a letter according the configured plug pairs
33 34 35 |
# File 'lib/enigma_machine/plugboard.rb', line 33 def substitute(letter) @mapping[letter] || letter end |
#translate(letter) ⇒ String
Translate a letter
This performs a substitution, calls the rotor to do the rest of the translation, and then substitutes the result on the way back out.
24 25 26 27 28 |
# File 'lib/enigma_machine/plugboard.rb', line 24 def translate(letter) step = substitute(letter) step = @decorated.translate(step) substitute(step) end |