Class: ShiftCiphers::Vigenere
- Inherits:
-
Object
- Object
- ShiftCiphers::Vigenere
- Defined in:
- lib/shift_ciphers/vigenere.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#alphabet ⇒ Object
Returns the value of attribute alphabet.
-
#key ⇒ Object
Returns the value of attribute key.
-
#nonalphabet_char_strategy ⇒ Object
Returns the value of attribute nonalphabet_char_strategy.
Class Method Summary collapse
Instance Method Summary collapse
- #decrypt(ciphertext) ⇒ Object
- #encrypt(plaintext) ⇒ Object
-
#initialize(key, alphabet: Alphabets::DEFAULT, nonalphabet_char_strategy: :error) ⇒ Vigenere
constructor
A new instance of Vigenere.
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
#alphabet ⇒ Object
Returns the value of attribute alphabet.
3 4 5 |
# File 'lib/shift_ciphers/vigenere.rb', line 3 def alphabet @alphabet end |
#key ⇒ Object
Returns the value of attribute key.
3 4 5 |
# File 'lib/shift_ciphers/vigenere.rb', line 3 def key @key end |
#nonalphabet_char_strategy ⇒ Object
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, **) self.new(key, **).decrypt(ciphertext) end |
.encrypt(plaintext, key, **options) ⇒ Object
67 68 69 |
# File 'lib/shift_ciphers/vigenere.rb', line 67 def encrypt(plaintext, key, **) self.new(key, **).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 |