godoor/hash/godoor_test.go

41 lines
950 B
Go
Raw Normal View History

2023-07-30 10:38:47 +00:00
package hash
import (
"fmt"
"testing"
)
func TestHash(t *testing.T) {
hash := HashCardUid(0x000000000F0AD2301)
if hash != "a6d9ba36ecb5f8e6312f40ee260ad59e9cca3c6ce073bf072df3324c0072886196e6823a7c758ab567fc53e91fbbda297a4efe0072e41316c56446ef126a5180" {
t.Errorf("WRONG Key generated: %q", hash)
}
hash = HashCardUid(0x3CBB5AAD)
if hash != "1e7bbc1aeeff4bfe58ea8d97df7cd0f97599fa31633d3a1f57d138549b3968c20affb186fe0b85570d34718b273d269bcd28b2be59faf8122451d91a2cdc5f18" {
t.Errorf("WRONG Key generated: %q", hash)
}
}
func TestBits(t *testing.T) {
bits := make([]bool, 64)
trueBits := []int{0, 1, 2, 3, 8, 10, 12, 13, 15, 18, 22, 23, 31}
for _, i := range trueBits {
bits[i] = true
}
var card uint64 = 0
for i := 63; i >= 0; i-- {
if bits[i] == true {
card |= 1 << (63 - i)
}
}
cardId := fmt.Sprintf("%x", card)
fmt.Println(cardId)
if card != 0xF0AD230100000000 {
panic(fmt.Errorf("WROOONG: %x", card))
}
}