Skip to content

Instantly share code, notes, and snippets.

@DavidJRobertson
Created April 9, 2012 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidJRobertson/2343131 to your computer and use it in GitHub Desktop.
Save DavidJRobertson/2343131 to your computer and use it in GitHub Desktop.
class String
def last(n)
self[-n,n]
end
end
require "digest"
def hash_message(message)
sha256 = Digest::SHA2.new(256)
sha256hash = sha256.digest message
binstring = ""
sha256hash.bytes.each do |byte|
binval = byte.to_s(2)
if binval.length < 8
binval = '0' * (8 - binval.length) + binval
end
binstring << binval
end
return binstring.last(50).to_i(2)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment