Class: Cipher::Wheatstone

Inherits:
Substitution show all
Includes:
Crypto
Defined in:
lib/cipher.rb

Overview

Wheatstone

Constant Summary

Constant Summary

Constants included from Crypto

Crypto::BASE

Instance Attribute Summary

Attributes inherited from Substitution

#key

Instance Method Summary (collapse)

Methods included from Crypto

#addmod10, #chainadd, #expand5to10, #find_hole, #keyshuffle, #normalize, #p1_encode, #str_to_numeric, #submod10

Methods inherited from Substitution

#decode

Methods inherited from SimpleCipher

#decode

Constructor Details

- (Wheatstone) initialize(start, plain, cipher)

initialize



334
335
336
# File 'lib/cipher.rb', line 334

def initialize(start, plain, cipher)
  @key = Key::Wheatstone.new(start, plain, cipher)
end

Instance Method Details

- (Object) encode(plain_text)

encode



340
341
342
343
344
345
346
347
348
349
# File 'lib/cipher.rb', line 340

def encode(plain_text)
  #
  # Doubled letters cc should be replaced by cQ
  #
  pl = plain_text.replace_double('Q')
  cipher_text = pl.each_char.inject('') do |text, pt|
    text + @key.encode(pt)
  end
  cipher_text
end