hashids-python icon indicating copy to clipboard operation
hashids-python copied to clipboard

How to use numbers only in alphabet

Open hcaihao opened this issue 6 years ago • 10 comments

I use

hashids = Hashids(salt="hello", min_length=6, alphabet='0123456789')

But "Alphabet must contain at least 16 unique characters." execption raised.

Why Alphabet must contain at least 16?

hcaihao avatar Jul 19 '19 12:07 hcaihao

The limit is most likely there for compatibility reasons, since this is a Python port of the JavaScript hashids implementation. The same limit is present in the JS source code.

On that note, I recommend this issue be closed.

malefice avatar Oct 04 '19 08:10 malefice

The lua port support number only alphabet, could you add an option to support this feature?

hcaihao avatar Oct 06 '19 03:10 hcaihao

Like I said, I think the limit is there for compatibility reasons with the JS implementation, and the maintainers/owner of the lua port probably thought that it is ok to add support for smaller alphabets. Whether it should be added here is up to the maintainers/owner of this port.

I am neither, so even if I submit a PR, it is still their decision. They have not even responded to this issue, and you created this issue almost 3 months ago. They have not even responded to my offer to help at #32. In any case, my use case does not need a smaller alphabet, so all things considered, I cannot allocate time to do this.

malefice avatar Oct 12 '19 09:10 malefice

Correct me if I am wrong here, but the request to use base 10 encoding for an integer which is already base 10... would just be substituting or ciphering.

see this link Base What?

lanningspencer avatar Oct 22 '19 19:10 lanningspencer

Apologies for the long silence here.

Yes, the limitation exists for compatibility with JS. I don’t have any strong opinions on that though, and if there’s interest I’d be happy to accept a PR that removes the limitation.

Thanks!

davidaurelio avatar Jul 14 '20 19:07 davidaurelio

I'd also prefer having 0123456789 as alphabet

sentiasa avatar Apr 07 '21 15:04 sentiasa

Apologies for the long silence here.

Yes, the limitation exists for compatibility with JS. I don’t have any strong opinions on that though, and if there’s interest I’d be happy to accept a PR that removes the limitation.

Thanks!

Would I be right in saying that this would simply be a case of removing the raise exception on line 194? Or is there more to it than that?

bodgerbarnett avatar Oct 27 '21 13:10 bodgerbarnett

@bodgerbarnett are you referring to [line 194 in the python implementation(https://github.com/davidaurelio/hashids-python/blob/master/hashids.py#L194)? Or do you mean line 185?

Honestly, in the end somebody would have to try it out. I can try working through the code at some point to see what possible detrimental effects of a small alphabet would be.

In any case, it is possible to use hex encoding (`alphabet='0123456789abcdef') and change the value to/from base 10 after encoding/before decoding.

davidaurelio avatar Nov 07 '21 21:11 davidaurelio

I use alphabet="0123456789cfhistu" to filter letter.

hcaihao avatar Aug 09 '22 09:08 hcaihao

its only support int value

aman-moweb avatar Jan 10 '23 07:01 aman-moweb