Class: Key::SCKey
Overview
SCKey
class for straddling checkerboard substitution keys
SC-keys needs to be condensed and rings generated for ciphering/deciphering
Constant Summary
- BASE =
'ABCDEFGHIJKLMNOPQRSTUVWXYZ/-'
Instance Attribute Summary (collapse)
-
- (Object) full_key
readonly
Returns the value of attribute full_key.
-
- (Object) longc
readonly
Returns the value of attribute longc.
-
- (Object) shortc
readonly
Returns the value of attribute shortc.
Attributes inherited from SKey
Instance Method Summary (collapse)
-
- (Object) gen_rings
gen_rings.
-
- (SCKey) initialize(key, longc = [ 8, 9 ])
constructor
A new instance of SCKey.
-
- (Boolean) is_long?(digit)
is_long?.
Methods included from Crypto
#addmod10, #chainadd, #expand5to10, #find_hole, #keyshuffle, #normalize, #p1_encode, #str_to_numeric, #submod10
Methods inherited from SKey
Constructor Details
- (SCKey) initialize(key, longc = [ 8, 9 ])
Returns a new instance of SCKey
26 27 28 29 30 31 |
# File 'lib/key/sckey.rb', line 26 def initialize(key, longc = [ 8, 9 ]) super(key) @longc = longc @full_key = keyshuffle(@key, BASE) gen_rings() end |
Instance Attribute Details
- (Object) full_key (readonly)
Returns the value of attribute full_key
24 25 26 |
# File 'lib/key/sckey.rb', line 24 def full_key @full_key end |
- (Object) longc (readonly)
Returns the value of attribute longc
24 25 26 |
# File 'lib/key/sckey.rb', line 24 def longc @longc end |
- (Object) shortc (readonly)
Returns the value of attribute shortc
24 25 26 |
# File 'lib/key/sckey.rb', line 24 def shortc @shortc end |
Instance Method Details
- (Object) gen_rings
gen_rings
Assign a code number for each letter. Each code number is sequentially allocated from two pools, one with 0..7 and the other with 80..99.
Allocation is made on the following criterias
-
if letter is one of ESANTIRU assign a single code number
-
else assign of of the two letters ones
Generate both the encoding and decoding rings.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/key/sckey.rb', line 45 def gen_rings shortc = (0..9).collect{|i| i unless @longc.include?(i) }.compact raise DataError if shortc.nil? long = @longc.collect{|i| (0..9).collect{|j| i*10+j } }.flatten raise DataError if long.nil? @shortc = shortc.dup word = @full_key.dup word.scan(/./) do |c| if 'ESANTIRU'.include? c then ind = shortc.shift else ind = long.shift end @alpha[c] = ind.to_s @ralpha[ind.to_s] = c end end |
- (Boolean) is_long?(digit)
is_long?
66 67 68 |
# File 'lib/key/sckey.rb', line 66 def is_long?(digit) return @longc.include?(digit) end |