Class: ShiftCiphers::Caesar

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

Constant Summary collapse

DEFAULT_OFFSET =
13

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#alphabetObject

Returns the value of attribute alphabet.



4
5
6
# File 'lib/shift_ciphers/caesar.rb', line 4

def alphabet
  @alphabet
end

#nonalphabet_char_strategyObject

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

#offsetObject

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, **options)
  self.new(**options).decrypt(ciphertext)
end

.encrypt(plaintext, **options) ⇒ Object



39
40
41
# File 'lib/shift_ciphers/caesar.rb', line 39

def encrypt(plaintext, **options)
  self.new(**options).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