Class: SHA0::Digest
- Inherits:
-
Object
- Object
- SHA0::Digest
- Defined in:
- lib/sha0.rb
Instance Method Summary collapse
- #digest ⇒ Object
- #hexdigest ⇒ Object
-
#initialize ⇒ Digest
constructor
A new instance of Digest.
- #update(data) ⇒ Object
Constructor Details
#initialize ⇒ Digest
Returns a new instance of Digest.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/sha0.rb', line 12 def initialize() @data = '' @data_length = 0 @hash = [ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 ] @rounds = 80 @tmp = [] @unit_size = 4 @block_size = 16 @block_byte_size = @block_size * @unit_size end |
Instance Method Details
#digest ⇒ Object
42 43 44 |
# File 'lib/sha0.rb', line 42 def digest current_hash.pack('N*') end |
#hexdigest ⇒ Object
46 47 48 49 50 |
# File 'lib/sha0.rb', line 46 def hexdigest() current_hash.each_with_object('') do |partial, hash| hash << '0' * (8 - partial.to_s(16).length) + partial.to_s(16) end end |
#update(data) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sha0.rb', line 29 def update(data) @data += data @data_length += data.size while @data.size >= @block_byte_size block = @data[0, @block_byte_size].unpack('N*') @hash = process_block(block) @data = @data[@block_byte_size, @data.size - @block_byte_size] end self end |