Class: DES::Block
- Inherits:
-
Object
- Object
- DES::Block
- Defined in:
- lib/des.rb
Instance Attribute Summary collapse
-
#bit_array ⇒ Object
(also: #to_a)
readonly
Returns the value of attribute bit_array.
-
#string ⇒ Object
(also: #to_s)
readonly
Returns the value of attribute string.
Instance Method Summary collapse
- #initialize(input) ⇒ NilClass constructor
Constructor Details
#initialize(input) ⇒ NilClass
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_array ⇒ Object (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 |
#string ⇒ Object (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 |