Class: RubyDES::Block
- Inherits:
-
Object
- Object
- RubyDES::Block
- Defined in:
- lib/ruby-des.rb
Instance Attribute Summary collapse
-
#bit_array ⇒ Object
readonly
Returns the value of attribute bit_array.
-
#string ⇒ Object
readonly
Returns the value of attribute string.
Instance Method Summary collapse
-
#initialize(input) ⇒ Block
constructor
A new instance of Block.
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_array ⇒ Object (readonly)
Returns the value of attribute bit_array.
73 74 75 |
# File 'lib/ruby-des.rb', line 73 def bit_array @bit_array end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
73 74 75 |
# File 'lib/ruby-des.rb', line 73 def string @string end |