Class: Key::SQKey
Overview
SQKey
Class for handling keys generated by a Polybius square.
XXX only 6x6 square is implemented in order to
-
have the full alphabet
-
have numbers as well
It also simplify the code
Constant Summary
- BASE36 =
'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
- SQ_NUMBERS =
1
- SQ_ADFGVX =
2
- CODE_WORD =
{ SQ_NUMBERS => [ 0, 1, 2, 3, 4, 5 ], SQ_ADFGVX => 'ADFGVX'.each_char.to_a }
Constants inherited from SKey
Instance Attribute Summary (collapse)
-
- (Object) full_key
readonly
Returns the value of attribute full_key.
-
- (Object) type
readonly
Returns the value of attribute type.
Attributes inherited from SKey
Instance Method Summary (collapse)
-
- (Object) gen_rings
gen_rings.
-
- (SQKey) initialize(key, type = SQ_ADFGVX)
constructor
A new instance of SQKey.
Methods inherited from SKey
Constructor Details
- (SQKey) initialize(key, type = SQ_ADFGVX)
Returns a new instance of SQKey
37 38 39 40 41 42 43 44 45 |
# File 'lib/key/sqkey.rb', line 37 def initialize(key, type = SQ_ADFGVX) super(key.gsub(%r{\s*}, '')) @alpha = Hash.new @ralpha = Hash.new @type = type @base = BASE36 @full_key = (@key + @base).condensed gen_rings end |
Instance Attribute Details
- (Object) full_key (readonly)
Returns the value of attribute full_key
35 36 37 |
# File 'lib/key/sqkey.rb', line 35 def full_key @full_key end |
- (Object) type (readonly)
Returns the value of attribute type
35 36 37 |
# File 'lib/key/sqkey.rb', line 35 def type @type end |
Instance Method Details
- (Object) gen_rings
gen_rings
Assign a code number/letter for each letter.
Generate both the encoding and decoding rings.
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/key/sqkey.rb', line 53 def gen_rings ind = 0 word = @full_key.dup CODE_WORD[@type].each do |i| CODE_WORD[@type].each do |j| c = word[ind] @alpha[c.chr] = "#{i}#{j}" @ralpha["#{i}#{j}"] = c.chr ind += 1 end end end |