Skip to content

Commit

Permalink
Adds hashrate
Browse files Browse the repository at this point in the history
  • Loading branch information
amir20 committed Nov 9, 2017
1 parent c0205fa commit 0ecee0d
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions test.go
@@ -1,11 +1,13 @@
package main

import (
"os"
"bytes"
"encoding/binary"
"crypto/sha256"
"encoding/binary"
"math/big"
"os"
"time"
"fmt"
)

func main() {
Expand All @@ -15,21 +17,27 @@ func main() {
buffer := make([]byte, total+8)
copy(buffer, bytes)

threshold := new(big.Int)
threshold.SetString("00000099999999999999999999999999999999999999999999999999999999999999999999999", 10)
var maxUint256 = new(big.Int).Exp(big.NewInt(2), big.NewInt(256), big.NewInt(0))
threshold := new(big.Int).Div(maxUint256, big.NewInt(1000000000))

start := time.Now()
found := int64(0)
for i := int64(0); i < 1<<63-1; i++ {
binary.PutVarint(buffer[total:], i)
sum := sha256.Sum256(buffer)

value := new(big.Int)
value.SetBytes(sum[:])
value := new(big.Int).SetBytes(sum[:])

if value.Cmp(threshold) < 0 {
println("Found match", value.String())
found = i
break
}
}

hashesPerSecond := found / int64(time.Since(start).Seconds())

fmt.Printf("Found a match with hashrate of %.2f MH/s\n", float32(hashesPerSecond)/float32(1000000))
}

func argToBytes() []byte {
Expand Down

0 comments on commit 0ecee0d

Please sign in to comment.