hashids / hashids.github.io

This is the old Hashids website. It is no longer maintained and has migrated over to Sqids.
https://sqids.org
206 stars 34 forks source link

Swift 4.2 not decoding properly #57

Closed ibyteapps closed 1 year ago

ibyteapps commented 4 years ago

I'm trying to implement this in Swift 4.2 but I can't seem to decode the strings properly.

I'm able to generate minHashLength 8 hash. But when I decode them and try changing say one letter at the end of the hash string, I still end up with the same hash many times.

Here's my code:

func getHashFromID (id : Int) -> String{ let hashids = Hashids(salt:mHashSalt,minHashLength: 8) let hash : String = hashids.encode(id) ?? "" return hash }

func getIDFromHash (mHash : String) -> Int{ let hashids = Hashids(salt:mHashSalt, minHashLength: 8) let numbers = hashids.decode( mHash ) print (String(format: "Decoding %@ - %d - %d - count - %d", mHash, numbers, numbers[0], numbers.count)) if (numbers.count>0){ return numbers[0] } return -1 }

I've implemented this successfully on Android, but the Swift version is giving me trouble in terms of decoding only.

4kimov commented 1 year ago

@ibyteapps Sorry for the late response.

Closing since the project is moving. New version of Swift is not implemented yet.