haochi / blockhash-go Goto Github PK
View Code? Open in Web Editor NEWBlockhash in golang
License: MIT License
Blockhash in golang
License: MIT License
It seems like something is off in the algorithm. The hash is sometimes correct, but not always.
Test code:
package main
import (
"os"
"fmt"
"github.com/jessevdk/go-flags"
"github.com/haochi/blockhash-go"
"github.com/dsoprea/go-logging"
)
type options struct {
Filepath string `short:"f" long:"filepath" required:"true" description:"File-path of image"`
}
func main() {
o := new(options)
if _, err := flags.Parse(o); err != nil {
os.Exit(1)
}
f, err := os.Open(o.Filepath)
log.PanicIf(err)
defer f.Close()
h, err := blockhash.Blockhash(f, 16)
log.PanicIf(err)
digest := h.ToHex()
fmt.Println(digest)
}
Using the Blockbash Python tool with four images (two valley scenes and two sizes of each, where one is full-sized and the other is scaled to 100-pixels wide):
$ python blockhash.py ~/Downloads/*jpg
1ffc3fff00fe000021ff7e3f0f8007c03fff1f8d0f9806003ffc3ff80f0400f0 /home/dustin/Downloads/20170618_155330.jpg
1ffc3fff00fe000031ff3e3f0f8007c03fff1f8d0f9806003ffc3ff80f0400f0 /home/dustin/Downloads/20170618_155330-small.jpg
7ff00fe00ff007e00ffd07f807f003f003fc07fa07f413f017f927e261cce0d8 /home/dustin/Downloads/amazing-mountain-valley-wallpaper-29910-30628-hd-wallpapers.jpg
7ff00fe00fe007f00ffd07f807f003f003fc07fa07f413f013f92fe261cce0d8 /home/dustin/Downloads/amazing-mountain-valley-wallpaper-29910-30628-hd-wallpapers-small.jpg
If I run the Go tool, I'l get:
$ go run blockhash-go-testing.go -f ~/Downloads/20170618_155330.jpg
1ffc3fff007e000021ff3e3f0f8007c03fff1f8c0f9806003ffc3ff80f0000f0
$ go run blockhash-go-testing.go -f ~/Downloads/20170618_155330-small.jpg
1ffc1fff007f000013ff3c3f0f8007c03ffa1f8e0f840e083ffc1ffc0fc00300
$ go run blockhash-go-testing.go -f ~/Downloads/amazing-mountain-valley-wallpaper-29910-30628-hd-wallpapers.jpg
7ff00fe00fe007e00ffd07f807f003e003fc03fa07f413f013f92fe261c4e0d8
$ go run blockhash-go-testing.go -f ~/Downloads/amazing-mountain-valley-wallpaper-29910-30628-hd-wallpapers-small.jpg
7ff00fe00fe007e007fc07f807f803f003fe03fe03f803f007fa1bf811f405e1
Notice that the full-size images have the same hashes as the Python tool, but the shrunk versions have a hash with a common-prefix (the first few characters are correct; the first seventeen characters in the first case and the first ten-characters in the other case) though the not all of the bytes match.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.