Module: CheckSum

Defined in:
lib/checksum.rb

Class Method Summary collapse

Class Method Details

.checksum(hex) ⇒ Object



12
13
14
15
# File 'lib/checksum.rb', line 12

def self.checksum(hex)
  hash = double_hash256(hex) # Hash the data through SHA256 twice

  return hash[0...8]  # Return the first 4 bytes (8 characters)

end

.double_hash256(hex) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/checksum.rb', line 4

def self.double_hash256(hex)
    binary = [hex].pack("H*")
    hash1 = Digest::SHA256.digest(binary)
    hash2 = Digest::SHA256.digest(hash1)
    result = hash2.unpack("H*")[0]
    return result
end