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.
-
#offset ⇒ Object
Returns the value of attribute offset.
Class Method Summary collapse
- .decrypt(cyphertext, offset = DEFAULT_OFFSET, alphabet = ALPHABET) ⇒ Object
- .encrypt(plaintext, offset = DEFAULT_OFFSET, alphabet = ALPHABET) ⇒ Object
Instance Method Summary collapse
- #decrypt(cyphertext) ⇒ Object
- #encrypt(plaintext) ⇒ Object
-
#initialize(offset = DEFAULT_OFFSET, alphabet = ALPHABET) ⇒ Caesar
constructor
A new instance of Caesar.
Constructor Details
#initialize(offset = DEFAULT_OFFSET, alphabet = ALPHABET) ⇒ Caesar
Returns a new instance of Caesar.
8 9 10 11 |
# File 'lib/shift_ciphers/caesar.rb', line 8 def initialize(offset = DEFAULT_OFFSET, alphabet = ALPHABET) @offset = offset @alphabet = alphabet end |
Instance Attribute Details
#alphabet ⇒ Object
Returns the value of attribute alphabet.
6 7 8 |
# File 'lib/shift_ciphers/caesar.rb', line 6 def alphabet @alphabet end |
#offset ⇒ Object
Returns the value of attribute offset.
6 7 8 |
# File 'lib/shift_ciphers/caesar.rb', line 6 def offset @offset end |
Class Method Details
.decrypt(cyphertext, offset = DEFAULT_OFFSET, alphabet = ALPHABET) ⇒ Object
26 27 28 |
# File 'lib/shift_ciphers/caesar.rb', line 26 def decrypt(cyphertext, offset = DEFAULT_OFFSET, alphabet = ALPHABET) process(cyphertext, offset, :decrypt, alphabet) end |
.encrypt(plaintext, offset = DEFAULT_OFFSET, alphabet = ALPHABET) ⇒ Object
22 23 24 |
# File 'lib/shift_ciphers/caesar.rb', line 22 def encrypt(plaintext, offset = DEFAULT_OFFSET, alphabet = ALPHABET) process(plaintext, offset, :encrypt, alphabet) end |
Instance Method Details
#decrypt(cyphertext) ⇒ Object
17 18 19 |
# File 'lib/shift_ciphers/caesar.rb', line 17 def decrypt(cyphertext) self.class.decrypt(cyphertext, offset, alphabet) end |
#encrypt(plaintext) ⇒ Object
13 14 15 |
# File 'lib/shift_ciphers/caesar.rb', line 13 def encrypt(plaintext) self.class.encrypt(plaintext, offset, alphabet) end |