Class: Cryptogram::Ciphers::Caesar
- Inherits:
-
BaseCipher
- Object
- BaseCipher
- Cryptogram::Ciphers::Caesar
- Defined in:
- lib/cryptogram/ciphers/caesar.rb
Instance Method Summary collapse
- #decrypt(string) ⇒ Object
- #encrypt(string) ⇒ Object
-
#initialize(alphabet:, shift:) ⇒ Caesar
constructor
A new instance of Caesar.
Constructor Details
#initialize(alphabet:, shift:) ⇒ Caesar
Returns a new instance of Caesar.
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 |