Class: Key::VICKey

Inherits:
Key
  • Object
show all
Includes:
Crypto
Defined in:
lib/key/vickey.rb

Overview

VICKey

The VIC cipher is described on the following Wikipedia page: en.wikipedia.org/wiki/VIC_cipher

and a working example is here: www.hypermaths.org/quadibloc/crypto/pp1324.htm

XXX Most of the arrays' content is 1-based mod 10 data (i.e. 0 == 10 and 1 is the lowest)

This uses a very complex key schedule as the basis of a straddling checkerboard.

Step1 uses Crypto.expand5to10 Step2 uses Crypto.chainadd on phrase (after conversion) Step3 uses the previously calculated data by running it 5 times through the Crypto.chainadd method. The key thus calculated is then converted through a transposition.

Constant Summary

Constant Summary

Constants included from Crypto

Crypto::BASE

Instance Attribute Summary (collapse)

Attributes inherited from Key

#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 Key

#condensed, #length, #to_s

Constructor Details

- (VICKey) initialize(ikey, phrase, imsg)

initialize



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/key/vickey.rb', line 41

def initialize(ikey, phrase, imsg)
  #
  # First phase
  #
  @ikey5 = str_to_numeric(ikey[0..4])
  @imsg = str_to_numeric(imsg)
  res = submod10(@imsg, @ikey5)
  @first = expand5to10(res)
  #
  # Second phase: we take the long numeric keys in two parts but we *must*
  # use normalize because String#to_numeric uses 0-based arrays) XXX
  #
  # We split the key phrase into two 10 digits parts @p1 & @p2
  # Then we add mod 10 @p1 and the first expanded ikey (as @first)
  #
  @p1 = normalize(phrase[0..9].to_numeric)
  @p2 = normalize(phrase[10..19].to_numeric)
  tmp = addmod10(@first, @p1)
  @second = p1_encode(tmp, @p2)
  #
  # Third phase
  #
  # We run 5 times through chainadd
  #
  r = @second.dup
  5.times do
    r = chainadd(r)
  end
  @third = r
  @sc_key = @third.join.to_numeric
end

Instance Attribute Details

- (Object) first (readonly)

Returns the value of attribute first



37
38
39
# File 'lib/key/vickey.rb', line 37

def first
  @first
end

- (Object) ikey5 (readonly)

Returns the value of attribute ikey5



37
38
39
# File 'lib/key/vickey.rb', line 37

def ikey5
  @ikey5
end

- (Object) p1 (readonly)

Returns the value of attribute p1



37
38
39
# File 'lib/key/vickey.rb', line 37

def p1
  @p1
end

- (Object) p2 (readonly)

Returns the value of attribute p2



37
38
39
# File 'lib/key/vickey.rb', line 37

def p2
  @p2
end

- (Object) sc_key (readonly)

Returns the value of attribute sc_key



37
38
39
# File 'lib/key/vickey.rb', line 37

def sc_key
  @sc_key
end

- (Object) second (readonly)

Returns the value of attribute second



37
38
39
# File 'lib/key/vickey.rb', line 37

def second
  @second
end

- (Object) third (readonly)

Returns the value of attribute third



37
38
39
# File 'lib/key/vickey.rb', line 37

def third
  @third
end