Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use numbers only in alphabet #31

Open
hcaihao opened this issue Jul 19, 2019 · 10 comments
Open

How to use numbers only in alphabet #31

hcaihao opened this issue Jul 19, 2019 · 10 comments

Comments

@hcaihao
Copy link

hcaihao commented Jul 19, 2019

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?

@malefice
Copy link

malefice commented Oct 4, 2019

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.

@hcaihao
Copy link
Author

hcaihao commented Oct 6, 2019

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

@malefice
Copy link

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.

@lanningspencer
Copy link

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?

@davidaurelio
Copy link
Owner

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!

@sentiasa
Copy link

sentiasa commented Apr 7, 2021

I'd also prefer having 0123456789 as alphabet

@bodgerbarnett
Copy link

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?

@davidaurelio
Copy link
Owner

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

@hcaihao
Copy link
Author

hcaihao commented Aug 9, 2022

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

@aman-moweb
Copy link

its only support int value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants