Class: ShiftCipher::Caesar

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

Constant Summary collapse

DEFAULT_OFFSET =
0
FIRST_UNICODE_CODEPOINT =
97
LAST_UNICODE_CODEPOINT =
123

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start = 0) ⇒ Caesar

Returns a new instance of Caesar.



10
11
12
# File 'lib/shift_cipher/caesar.rb', line 10

def initialize(start = 0)
  @offset = calculate_offset(start)
end

Instance Attribute Details

#offsetObject

Returns the value of attribute offset.



8
9
10
# File 'lib/shift_cipher/caesar.rb', line 8

def offset
  @offset
end

Instance Method Details

#decrypt(message) ⇒ Object



18
19
20
# File 'lib/shift_cipher/caesar.rb', line 18

def decrypt(message)
  shift(message, -offset)
end

#encrypt(message) ⇒ Object



14
15
16
# File 'lib/shift_cipher/caesar.rb', line 14

def encrypt(message)
  shift(message, offset)
end