Class: RubyDES::Block

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Block

Returns a new instance of Block.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/ruby-des.rb', line 75

def initialize(input)
  if input.is_a?(String)
    raise "RubyDES::InvalidStringLength: Input String 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 "RubyDES::InvalidArraySize: Input Array must contain (64) bits." unless input.size.eql?(64)
    
    @string    = input.join.to_a.pack('B*')
    @bit_array = input
  else
    raise "RubyDES::InvalidFormat: Input must be a String or an Array."
  end
end

Instance Attribute Details

#bit_arrayObject (readonly)

Returns the value of attribute bit_array.



73
74
75
# File 'lib/ruby-des.rb', line 73

def bit_array
  @bit_array
end

#stringObject (readonly)

Returns the value of attribute string.



73
74
75
# File 'lib/ruby-des.rb', line 73

def string
  @string
end