Compare commits
No commits in common. "master" and "v1.0.2" have entirely different histories.
@ -21,7 +21,6 @@ Usage:
|
||||
hashcash new [subject *] [expires in 5m] [difficulty 10]
|
||||
hashcash parse <hashcash>
|
||||
hashcash solve <hashcash>
|
||||
hashcash hash <hashcash>
|
||||
hashcash verify <hashcash> [subject *]
|
||||
```
|
||||
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
@ -17,7 +15,6 @@ func help() {
|
||||
fmt.Println("\thashcash new [subject *] [difficulty 10] [expires in 5m]")
|
||||
fmt.Println("\thashcash parse <hashcash>")
|
||||
fmt.Println("\thashcash solve <hashcash>")
|
||||
fmt.Println("\thashcash hash <hashcash>")
|
||||
fmt.Println("\thashcash verify <hashcash> [subject *]")
|
||||
}
|
||||
|
||||
@ -110,17 +107,6 @@ func main() {
|
||||
|
||||
fmt.Println(h.String())
|
||||
return
|
||||
case "hash":
|
||||
var token string
|
||||
if 3 != nargs {
|
||||
help()
|
||||
os.Exit(1)
|
||||
return
|
||||
}
|
||||
token = args[2]
|
||||
hash := sha256.Sum256([]byte(token))
|
||||
fmt.Println(hex.EncodeToString(hash[:]))
|
||||
return
|
||||
case "verify":
|
||||
var token string
|
||||
if nargs < 3 {
|
||||
|
||||
13
hashcash.go
13
hashcash.go
@ -216,10 +216,6 @@ func (h *Hashcash) Verify(subject string) error {
|
||||
}
|
||||
|
||||
func verifyBits(hash []byte, bits, n int) bool {
|
||||
if 0 == bits {
|
||||
return true
|
||||
}
|
||||
|
||||
for i := 0; i < n; i++ {
|
||||
if bits > 8 {
|
||||
bits -= 8
|
||||
@ -231,12 +227,15 @@ func verifyBits(hash []byte, bits, n int) bool {
|
||||
|
||||
// (bits % 8) == bits
|
||||
pad := 8 - bits
|
||||
if 0 == hash[i]>>pad {
|
||||
return true
|
||||
if 0 != hash[i]>>pad {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
// 0 == bits
|
||||
return true
|
||||
}
|
||||
|
||||
// Solve will search for a solution, returning an error if the difficulty is
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user