Class: HSMR::Component

Inherits:
Object
  • Object
show all
Includes:
HSMR
Defined in:
lib/hsmr/component.rb

Constant Summary

Constants included from HSMR

DOUBLE, SINGLE, TRIPLE, VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HSMR

cvv, decimalise, decrypt_pin, encrypt, encrypt_pin, #generate, ibm3624, #kcv, numeric?, #odd_parity?, #parity, pvv, #set_odd_parity, to_binary, to_hex, #to_s, #xor, xor, #xor!

Constructor Details

#initialize(key = nil, length = DOUBLE) ⇒ Component

Returns a new instance of Component.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/hsmr/component.rb', line 11

def initialize(key=nil, length=DOUBLE)
  ## Should check for odd parity
  if key.nil?
    key = generate(length)
  else
    key=key.gsub(/ /,'')
    #raise TypeError, "Component argument expected" unless other.is_a? Component
  end
  @key = key.unpack('a2'*(key.length/2)).map{|x| x.hex}.pack('c'*(key.length/2))
  @length = @key.length
  @key = @key
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



4
5
6
# File 'lib/hsmr/component.rb', line 4

def key
  @key
end

#lengthObject (readonly)

Returns the value of attribute length.



5
6
7
# File 'lib/hsmr/component.rb', line 5

def length
  @length
end

Instance Method Details

#componentObject



7
8
9
# File 'lib/hsmr/component.rb', line 7

def component
  @key
end