Skip to content

Instantly share code, notes, and snippets.

@hkparker
Last active August 29, 2015 14:00
Show Gist options
  • Save hkparker/11309615 to your computer and use it in GitHub Desktop.
Save hkparker/11309615 to your computer and use it in GitHub Desktop.
Simple demonstration of hashcash in ruby
#!/usr/bin/env ruby
require 'digest'
require 'securerandom'
difficulty = 6
message = "hello"
hash = "1"*difficulty
random_value = nil
until hash[0..difficulty-1] == "0"*difficulty
random_value = SecureRandom.hex.to_s
hash = (Digest::SHA1.hexdigest(message+random_value)).to_s
end
puts "#{hash} generated with random value #{random_value}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment