Heads up: This description was created by AI and might not be 100% accurate.
md5sum.rb
This Ruby code snippet demonstrates the use of the Digest::MD5
module for calculating MD5 hash values.
- It first requires the
digest/md5
library. Digest::MD5.hexdigest("ruby")
calculates the MD5 hash of the string “ruby” and returns it as a hexadecimal string (“58e53d1324eef6265fdb97b08ed9aadf”).Digest::MD5.file('input/digest/md5sum.rb').to_s
calculates the MD5 hash of the contents of the file ‘input/digest/md5sum.rb’ and returns it as a hexadecimal string (“b9e992f67fcc4e238d9964a07aba6dd7”).
Ruby code snippet
require 'digest/md5'
#=> true
Digest::MD5.hexdigest("ruby")
#=> "58e53d1324eef6265fdb97b08ed9aadf"
Digest::MD5.file('input/digest/md5sum.rb').to_s
#=> "b9e992f67fcc4e238d9964a07aba6dd7"
Executed with Ruby 3.4.5
.