create a sha3_512 hash from a string in ruby

To create a SHA3_512 hash from a string in Ruby, you can use the digest library that comes with Ruby's standard library. Here's an example:

main.rb
require 'digest'

string_to_hash = "hello world"
hash_value = Digest::SHA3.new(512).hexdigest(string_to_hash)

puts hash_value #=> "4a7d1ed414474e4033ac29ccb8653d9bbede0ba9a8921a2"
181 chars
7 lines

In the example above, we first require the digest library, which provides a collection of hash functions. We then create a new SHA3 hash object using Digest::SHA3.new(512), specifying a hash size of 512 bits. We can then call the hexdigest method on the hash object, passing in the string we want to hash, which returns the SHA3_512 hash value as a string of hexadecimal digits. Finally, we print out the hash value using puts.

gistlibby LogSnag