speps/go-hashids

Epoch hashing

ssorenso opened this issue · 1 comments

Hi Team,

I don't know whether or not you think this is a valid bug or not.

If I do something like:

// HashMaker performs a salted hash based upon epoch
func HashMaker() string {
	now := time.Now()
	hash := hashids.NewData()
	value := now.Unix()
	hash.Salt = "hello world"
	h, _ := hashids.NewWithData(hash)
	e, _ := h.Encode(toIntSlice(string(value)))
	got, _ := h.DecodeWithError(e)
	fmt.Println("should be", value, "got", got)

	return e
}

I get something like:

should be 1538515448 got [65533]
jolM
should be 1538515449 got [65533]
jolM
should be 1538515450 got [65533]
jolM
should be 1538515451 got [65533]
jolM

I guess that my expectation is to see something like:

should be <epoch> got <epoch>
<hash>

I am sending the epoch as a string into the hash as data, and I can replace it for the salt as well, and it results in the same problem.

speps commented

It would be good to see your toIntSlice method, as I think you should be able to encode the epoch directly instead of having to make it into multiple numbers using EncodeInt64. I added a new test in 6ba254b that shows how to do it.