Class: Cipher::Playfair
- Inherits:
-
BiGrammatic
- Object
- SimpleCipher
- Substitution
- BiGrammatic
- Cipher::Playfair
- Defined in:
- lib/cipher/playfair.rb
Overview
Playfair
Bigrammatic substitution through a square alphabet
Alphabet is missing Q by default
Instance Attribute Summary
Attributes inherited from Substitution
Instance Method Summary (collapse)
-
- (Object) encode(plain_text)
encode.
-
- (Playfair) initialize(key, type = Key::Playfair::WITH_Q)
constructor
initialize.
Methods inherited from BiGrammatic
Methods inherited from Substitution
Methods inherited from SimpleCipher
Constructor Details
- (Playfair) initialize(key, type = Key::Playfair::WITH_Q)
initialize
23 24 25 |
# File 'lib/cipher/playfair.rb', line 23 def initialize(key, type = Key::Playfair::WITH_Q) super(Key::Playfair, key, type) end |
Instance Method Details
- (Object) encode(plain_text)
encode
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/cipher/playfair.rb', line 29 def encode(plain_text) # # Do expand the double letters inside # plain = plain_text. # Add a "X" if of odd length # if plain.length.odd? then plain << "X" end check_input(plain) cipher_text = plain.scan(/../).inject('') do |text, pt| text + @key.encode(pt) end return cipher_text end |