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
}
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.