Re: Ruby Quiz - Challenge #5 - Crypto Mining - Find the Winning Lucky Number - Nonce (=Number used ONCE) for the Proof-of-Work (PoW) Hash (SHA-256)

Ryan Davis <[email protected]>
Newsgroups gmane.comp.lang.ruby.general
Message-ID <[email protected]>

> On Nov 17, 2018, at 09:44, Frank J. Cameron <[email protected]> wrote:
> 
> class RubyQuizTest
>  def compute_nonce(data)
>    0.upto(Float::INFINITY) do |nonce|
>      break nonce if sha256("#{nonce}#{data}", 2)==0
>    end
>  end
>  require 'inline'
>  inline do |builder|
>    builder.include '<string.h>'
>    builder.include '<openssl/sha.h>'
>    builder.c <<-END
>      int sha256(char * s, int difficulty) {
>        unsigned char * d = SHA256((unsigned char *)s, strlen(s), 0);
>        for(int i=0; i<difficulty; i++) if (d[i] != 0) return -1;
>        return 0;
>      }
>    END
>  end
> end
> RubyQuizTest.new('fjc’)

Daaaaamn… good job! It’s so rare to see inline used in the wild!

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.