-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
100 lines (82 loc) · 1.98 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package main
import (
"encoding/hex"
"flag"
"fmt"
"github.com/rb-de0/lyra2rev2"
"github.com/rb-de0/lyra2rev2/sha3"
"github.com/aead/skein"
"github.com/dchest/blake256"
)
type HashCalculator = func([]byte) []byte
func main() {
defer func() {
if r := recover(); r != nil {
fmt.Println("Recover Panic Error:", r)
}
}()
hashCalculators := map[string]HashCalculator{}
hashCalculators["lyra2rev2"] = func(input []byte) []byte {
data := make([]byte, 80)
copy(data, input)
result, err := lyra2rev2.Sum(data)
if err != nil {
panic(err)
}
return result
}
hashCalculators["blake"] = func(input []byte) []byte {
blake := blake256.New()
if _, err := blake.Write(input); err != nil {
panic(err)
}
result := blake.Sum(nil)
return result
}
hashCalculators["keccak"] = func(input []byte) []byte {
keccak := sha3.NewKeccak256()
if _, err := keccak.Write(input); err != nil {
panic(err)
}
result := keccak.Sum(nil)
return result
}
hashCalculators["cubehash"] = func(input []byte) []byte {
return lyra2rev2.Cubehash256(input)
}
hashCalculators["lyra2"] = func(input []byte) []byte {
result := make([]byte, 32)
lyra2rev2.Lyra2(result, input, input, 1, 4, 4)
return result
}
hashCalculators["skein"] = func(input []byte) []byte {
var result [32]byte
skein.Sum256(&result, input, nil)
return result[:]
}
hashCalculators["bmw"] = func(input []byte) []byte {
return lyra2rev2.Bmw256(input)
}
flag.Parse()
hash := flag.Arg(0)
calculator, exist := hashCalculators[hash]
if exist {
input := flag.Arg(1)
inputBytes, err := hex.DecodeString(input)
if err != nil {
panic(err)
}
result := calculator(inputBytes)
fmt.Println(hash + " result: " + hex.EncodeToString(result))
} else {
input := flag.Arg(0)
inputBytes, err := hex.DecodeString(input)
if err != nil {
panic(err)
}
for key := range hashCalculators {
result := hashCalculators[key](inputBytes)
fmt.Println(key + " : " + hex.EncodeToString(result))
}
}
}