Created
November 5, 2013 18:17
-
-
Save dmerrick/7323542 to your computer and use it in GitHub Desktop.
this is a simple script to generate checksums and find ones that start with zeros. when a matching checksum is found, it outputs it and looks for the a checksum with one more zero.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # this is a simple script to generate checksums and | |
| # find ones that start with zeros. when a matching | |
| # checksum is found, it outputs it and looks for | |
| # the a checksum with one more zero. | |
| # you can see in the output below that it took only | |
| # 9 tries to find a checksum with one zero, and it | |
| # took 6132845 tries to find one with six zeros. | |
| # example output: | |
| # 9 0ade7c2cf97f75d009975f4d720d1fa6c19f4897 | |
| # 127 008451a05e1e7aa32c75119df950d405265e0904 | |
| # 6117 00078f66cd4321af437c7d9486bacb3b3b187328 | |
| # 16055 000055d41c8a62052dd426592e8a4a3342bf565d | |
| # 946399 00000cb4a5d760de88fecb38e2f71b7bec52e834 | |
| # 6132845 00000055a78bf6735c4a89358fab1de34104c3cb | |
| # | |
| # code follows | |
| # (you are not expected to understand it) | |
| # | |
| # this provides the "hexdigest" function we use later | |
| require 'digest/sha1' | |
| # this is the value we're checksumming/incrementing | |
| # c.p. https://en.wikipedia.org/wiki/Cryptographic_nonce | |
| nonce = 0 | |
| # this is the number of zeros we're looking for | |
| # we start with a single zero, and once we find a | |
| # matching checksum we will look for 2, 3, 4, etc. | |
| zeros = 1 | |
| loop do | |
| # make a checksum from the nonce | |
| checksum = Digest::SHA1.hexdigest nonce.to_s | |
| # if the checksum starts with the right number of zeros... | |
| if checksum =~ /^0{1,#{zeros}}+/ | |
| # ...print the checksum and the nonce... | |
| puts nonce.to_s + "\t" + checksum | |
| # ...and then increment the number of zeros we're looking for | |
| zeros += 1 | |
| end | |
| # move on to the next nonce | |
| nonce += 1 | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment