Class: Wixy::Vigenere

Inherits:
Object
  • Object
show all
Defined in:
lib/wixy/vigenere.rb

Instance Method Summary collapse

Constructor Details

#initialize(config = Config.new) ⇒ Vigenere

Returns a new instance of Vigenere.



6
7
8
9
10
# File 'lib/wixy/vigenere.rb', line 6

def initialize(config = Config.new)
  @config = config
  @alphabet = Alphabet.AZ
  @key = @alphabet.sanitize(config.key)
end

Instance Method Details

#decrypt(text) ⇒ Object



17
18
19
20
# File 'lib/wixy/vigenere.rb', line 17

def decrypt(text)
  shift = -> index, offset { index - offset }
  solve text, shift
end

#encrypt(text) ⇒ Object



12
13
14
15
# File 'lib/wixy/vigenere.rb', line 12

def encrypt(text)
  shift = -> index, offset { index + offset }
  solve text, shift
end