Class: ShiftCiphers::Caesar
- Inherits:
-
Object
- Object
- ShiftCiphers::Caesar
- Defined in:
- lib/shift_ciphers/caesar.rb
Constant Summary collapse
- DEFAULT_OFFSET =
13
Instance Attribute Summary collapse
-
#alphabet ⇒ Object
Returns the value of attribute alphabet.
-
#nonalphabet_char_strategy ⇒ Object
Returns the value of attribute nonalphabet_char_strategy.
-
#offset ⇒ Object
Returns the value of attribute offset.
Class Method Summary collapse
Instance Method Summary collapse
- #decrypt(ciphertext) ⇒ Object
- #encrypt(plaintext) ⇒ Object
-
#initialize(offset: DEFAULT_OFFSET, alphabet: Alphabets::DEFAULT, nonalphabet_char_strategy: :error) ⇒ Caesar
constructor
A new instance of Caesar.
Constructor Details
#initialize(offset: DEFAULT_OFFSET, alphabet: Alphabets::DEFAULT, nonalphabet_char_strategy: :error) ⇒ Caesar
Returns a new instance of Caesar.
6 7 8 9 10 |
# File 'lib/shift_ciphers/caesar.rb', line 6 def initialize(offset: DEFAULT_OFFSET, alphabet: Alphabets::DEFAULT, nonalphabet_char_strategy: :error) @offset = offset @alphabet = alphabet @nonalphabet_char_strategy = nonalphabet_char_strategy end |
Instance Attribute Details
#alphabet ⇒ Object
Returns the value of attribute alphabet.
4 5 6 |
# File 'lib/shift_ciphers/caesar.rb', line 4 def alphabet @alphabet end |
#nonalphabet_char_strategy ⇒ Object
Returns the value of attribute nonalphabet_char_strategy.
4 5 6 |
# File 'lib/shift_ciphers/caesar.rb', line 4 def nonalphabet_char_strategy @nonalphabet_char_strategy end |
#offset ⇒ Object
Returns the value of attribute offset.
4 5 6 |
# File 'lib/shift_ciphers/caesar.rb', line 4 def offset @offset end |
Class Method Details
.decrypt(ciphertext, **options) ⇒ Object
43 44 45 |
# File 'lib/shift_ciphers/caesar.rb', line 43 def decrypt(ciphertext, **) self.new(**).decrypt(ciphertext) end |
.encrypt(plaintext, **options) ⇒ Object
39 40 41 |
# File 'lib/shift_ciphers/caesar.rb', line 39 def encrypt(plaintext, **) self.new(**).encrypt(plaintext) end |
Instance Method Details
#decrypt(ciphertext) ⇒ Object
16 17 18 |
# File 'lib/shift_ciphers/caesar.rb', line 16 def decrypt(ciphertext) process(ciphertext, false) end |
#encrypt(plaintext) ⇒ Object
12 13 14 |
# File 'lib/shift_ciphers/caesar.rb', line 12 def encrypt(plaintext) process(plaintext, true) end |