Class: ShiftCiphers::Vigenere

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

Direct Known Subclasses

HardenedVigenere

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, alphabet: Alphabets::DEFAULT, nonalphabet_char_strategy: :error) ⇒ Vigenere

Returns a new instance of Vigenere.



5
6
7
8
9
10
11
# File 'lib/shift_ciphers/vigenere.rb', line 5

def initialize(key, alphabet: Alphabets::DEFAULT, nonalphabet_char_strategy: :error)
  validate_key(key, alphabet)
  @key = key
  @alphabet = alphabet
  @nonalphabet_char_strategy = nonalphabet_char_strategy
  set_key_offsets
end

Instance Attribute Details

#alphabetObject

Returns the value of attribute alphabet.



3
4
5
# File 'lib/shift_ciphers/vigenere.rb', line 3

def alphabet
  @alphabet
end

#keyObject

Returns the value of attribute key.



3
4
5
# File 'lib/shift_ciphers/vigenere.rb', line 3

def key
  @key
end

#nonalphabet_char_strategyObject

Returns the value of attribute nonalphabet_char_strategy.



3
4
5
# File 'lib/shift_ciphers/vigenere.rb', line 3

def nonalphabet_char_strategy
  @nonalphabet_char_strategy
end

Class Method Details

.decrypt(ciphertext, key, **options) ⇒ Object



71
72
73
# File 'lib/shift_ciphers/vigenere.rb', line 71

def decrypt(ciphertext, key, **options)
  self.new(key, **options).decrypt(ciphertext)
end

.encrypt(plaintext, key, **options) ⇒ Object



67
68
69
# File 'lib/shift_ciphers/vigenere.rb', line 67

def encrypt(plaintext, key, **options)
  self.new(key, **options).encrypt(plaintext)
end

Instance Method Details

#decrypt(ciphertext) ⇒ Object



28
29
30
# File 'lib/shift_ciphers/vigenere.rb', line 28

def decrypt(ciphertext)
  process(ciphertext, false)
end

#encrypt(plaintext) ⇒ Object



24
25
26
# File 'lib/shift_ciphers/vigenere.rb', line 24

def encrypt(plaintext)
  process(plaintext, true)
end