Class: Enygma::Rotator

Inherits:
Object
  • Object
show all
Defined in:
lib/enygma/helpers/rotator.rb

Class Method Summary collapse

Class Method Details

.rotate(key_character_1, key_character_2, offset_character, character) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/enygma/helpers/rotator.rb', line 5

def self.rotate(
  key_character_1,
  key_character_2,
  offset_character,
  character
)
  character_index = Enygma::CHARACTER_MAP.index(character)
  total_shift = (key_character_1 + key_character_2).to_i +
    offset_character.to_i
  rotation = yield(character_index, total_shift)
  rotation % Enygma::CHARACTER_MAP.size
end