-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhwlds512.go
42 lines (39 loc) · 941 Bytes
/
hwlds512.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
/*
HWLDS (Hash with length-dependent security)
512 Bits
*/
package hash_algos
import (
"encoding/hex"
"errors"
)
func hwlds512(inputString string) string {
if inputString == "" {
_ = errors.New("HWLDS Hash Error: Empty input")
}
var result []byte = []byte(inputString)
var helpers = []byte{0b00000000}
for i := 0; i < 128-len(result); i++ {
result = append(result, helpers[0])
}
var x int = 0
for y := range result {
if x == len(helpers) {
x = 0
}
result[y] ^= helpers[x]&result[y] | (result[y] << 2)
for z := len(result) - 1; z >= 0; z-- {
helpers = append(helpers, result[y]^result[z]<<helpers[x])
for h := range helpers {
helpers[h] = helpers[h] ^ helpers[x+1]
}
for h := range helpers {
result[x] = result[y] ^ helpers[h]
}
result[z] = result[z] ^ (helpers[x] | result[y])
result[y] ^= result[z]
}
x++
}
return hex.EncodeToString(result[len(result)-65 : len(result)-1])
}