Skip to content

Commit

Permalink
Parsing the hash of the string type
Browse files Browse the repository at this point in the history
When we have a hash, we can use this function to get the object to compare
  • Loading branch information
python333 committed Mar 3, 2018
1 parent 0057c01 commit 8052b87
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tlsh.go
Expand Up @@ -65,6 +65,22 @@ func (t *Tlsh) String() string {
return hex.EncodeToString(t.Binary())
}

// Parsing the hash of the string type
func ParseStringToTlsh(hashString string) (*Tlsh, error) {
var code [codeSize]byte
hashByte, err := hex.DecodeString(hashString)
if err != nil {
return &Tlsh{}, err
}
chechsum := swapByte(hashByte[0])
lValue := swapByte(hashByte[1])
qRatio := hashByte[2]
q1Ratio := (qRatio >> 4) & 0xF
q2Ratio := qRatio & 0xF
copy(code[:], hashByte[3:])
return New(chechsum, lValue, q1Ratio, q2Ratio, qRatio, code), nil
}

func quartilePoints(buckets [numBuckets]uint) (q1, q2, q3 uint) {
var spl, spr uint
p1 := uint(effBuckets/4 - 1)
Expand Down

0 comments on commit 8052b87

Please sign in to comment.