Class: Cryptogram::Ciphers::Caesar

Inherits:
BaseCipher show all
Defined in:
lib/cryptogram/ciphers/caesar.rb

Instance Method Summary collapse

Constructor Details

#initialize(alphabet:, shift:) ⇒ Caesar

Returns a new instance of Caesar.

Parameters:

  • alphabet (Array, Symbol)

    Array of chars or presetted alphabet name

  • shift (Integer)

    Encryption shift



10
11
12
13
14
# File 'lib/cryptogram/ciphers/caesar.rb', line 10

def initialize(alphabet:, shift:)
  super(alphabet: alphabet)

  @mapper = ::Cryptogram::Mapper.new(alphabet: @alphabet, shift: shift)
end

Instance Method Details

#decrypt(string) ⇒ Object



20
21
22
# File 'lib/cryptogram/ciphers/caesar.rb', line 20

def decrypt(string)
  process(string) { |char| @mapper.map_to_initial(char) }
end

#encrypt(string) ⇒ Object



16
17
18
# File 'lib/cryptogram/ciphers/caesar.rb', line 16

def encrypt(string)
  process(string) { |char| @mapper.map_to_shifted(char) }
end