Class: DES::Block

Inherits:
Object
  • Object
show all
Defined in:
lib/des.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ NilClass

Parameters:



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/des.rb', line 78

def initialize(input)
  if input.is_a?(String)
    raise "DES::InvalidStringLength: Input String '#{input}' must contain (8) characters." unless input.length.eql?(8)

    @string = input
    @bit_array = input.unpack('B*').join.split('').collect { |b| b.to_i }
  elsif input.is_a?(Array)
    raise 'DES::InvalidArraySize: Input Array must contain (64) bits.' unless input.size.eql?(64)

    @string = input.join.lines.to_a.pack('B*')
    @bit_array = input
  else
    raise 'DES::InvalidFormat: Input must be a String or an Array.'
  end
end

Instance Attribute Details

#bit_arrayObject (readonly) Also known as: to_a

Returns the value of attribute bit_array.



71
72
73
# File 'lib/des.rb', line 71

def bit_array
  @bit_array
end

#stringObject (readonly) Also known as: to_s

Returns the value of attribute string.



71
72
73
# File 'lib/des.rb', line 71

def string
  @string
end