Class: Cipher::Substitution
- Inherits:
-
SimpleCipher
- Object
- SimpleCipher
- Cipher::Substitution
- Defined in:
- lib/cipher/subst.rb
Overview
Substitution
Class for substitution cipher (Caesar, Polyalphabetic, Nihilist)
Direct Known Subclasses
BiGrammatic, Caesar, ChaoCipher, Rot13, StraddlingCheckerboard, Wheatstone
Instance Attribute Summary (collapse)
-
- (Object) key
readonly
Returns the value of attribute key.
Instance Method Summary (collapse)
-
- (Object) decode(cipher_text)
decode.
-
- (Object) encode(plain_text)
encode.
-
- (Substitution) initialize(key = '')
constructor
initialize.
Constructor Details
- (Substitution) initialize(key = '')
initialize
21 22 23 |
# File 'lib/cipher/subst.rb', line 21 def initialize(key = '') @key = Key::SKey.new(key) end |
Instance Attribute Details
- (Object) key (readonly)
Returns the value of attribute key
17 18 19 |
# File 'lib/cipher/subst.rb', line 17 def key @key end |
Instance Method Details
- (Object) decode(cipher_text)
decode
36 37 38 39 40 41 |
# File 'lib/cipher/subst.rb', line 36 def decode(cipher_text) plain_text = cipher_text.each_char.inject('') do |text, ct| text + @key.decode(ct) end return plain_text end |
- (Object) encode(plain_text)
encode
27 28 29 30 31 32 |
# File 'lib/cipher/subst.rb', line 27 def encode(plain_text) cipher_text = plain_text.each_char.inject('') do |text, pt| text + @key.encode(pt) end return cipher_text end |