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

Is "minAlphabetLength = 16" required? #21

Closed
liukun opened this issue Dec 12, 2015 · 9 comments
Closed

Is "minAlphabetLength = 16" required? #21

liukun opened this issue Dec 12, 2015 · 9 comments

Comments

@liukun
Copy link

liukun commented Dec 12, 2015

I tried only use numbers as alphabet, and seems worked:

coffee> hashids = new hashids "aaa", 9, "0123456789"
{ version: '0.3.3',
  minAlphabetLength: 2,
  sepDiv: 3.5,
  guardDiv: 12,
  errorAlphabetLength: 'error: alphabet must contain at least X unique characters',
  errorAlphabetSpace: 'error: alphabet cannot contain spaces',
  alphabet: '347895',
  seps: '012',
  minHashLength: 9,
  salt: 'aaa',
  guards: '6' }
coffee> hashids.encrypt 1
'547645689'
coffee> hashids.decrypt '547645689'
[ 1 ]

Are there some implicit requirements in algorithm?

@jd327
Copy link
Collaborator

jd327 commented Dec 12, 2015

Looks like you're using a bit of an older version, where min length is 2. But for newer versions, check out these comments as to why 16 is minimum:

@jd327 jd327 closed this as completed Dec 12, 2015
@liukun
Copy link
Author

liukun commented Dec 14, 2015

Thank you very much! So I can just use alphabet "0123456789cfhistuCFHISTU" to achieve my goal that only use 0123456789 as characters of the generated id when not need seperators.

coffee> hashids = new (require 'hashids') "aaa", 9, "0123456789cfhistuCFHISTU"
{ version: '1.0.2',
  minAlphabetLength: 16,
  sepDiv: 3.5,
  guardDiv: 12,
  errorAlphabetLength: 'error: alphabet must contain at least X unique characters',
  errorAlphabetSpace: 'error: alphabet cannot contain spaces',
  alphabet: '602137945',
  seps: 'IcHFihUufCStsT',
  minHashLength: 9,
  salt: 'aaa',
  guards: '8' }
coffee> hashids.encode 1
'120805874'
coffee> hashids.encode 100000
'869749698'
coffee> hashids.decode '120805874'
[ 1 ]

@jd327
Copy link
Collaborator

jd327 commented Dec 14, 2015

Yes. Also for your use-case, check out #3 on this: http://hashids.org/#alternatives

@liukun
Copy link
Author

liukun commented Dec 15, 2015

@ivanakimov Great! Thanks for the info.
In my case, an user may need to input id by hand, so I think hashids is better because the generated string could have shorter length compared to Optimus'.

@godbout
Copy link

godbout commented Mar 17, 2018

I'm using "0123456789cfhistuCFHISTU" too, and I only get numbers which is what I'm looking for, but I don't understand why 😂️

It is said that "the algorithm tries to avoid generating most common English curse words by never placing the following letters (and their uppercase equivalents) next to each other". So, how is it that those letters are not even found one time in the generated hashids? It could be put between 2 numbers, no?

@liukun
Copy link
Author

liukun commented Mar 19, 2018

@godbout IIRC those characters are used for separators when you encoding an array

@godbout
Copy link

godbout commented Mar 19, 2018

@liukun yeah I saw that in the doc, but from what I understood from the doc and the source, those letters could still show up in the generated hashid. But like you, I just receive numbers, which I find very strange (although this is what I want, but I can't confirm that it would then work all the time?). I don't use Optimus neither because I want to control the length of the numbers generated.

@liukun
Copy link
Author

liukun commented Mar 19, 2018

@godbout Array separator

> hashids.encode(1)
'120805874'
> hashids.encode(2)
'347821860'
> hashids.encode([1,2]) // array
'24815c381'
> hashids.encode([1,2,3,4]) // array
'805c4H9F9'

@godbout
Copy link

godbout commented Mar 19, 2018

🤦🏻‍♂️😂

Got it sorry. Holiday mood 😂
Thanks a lot!

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

3 participants