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

Generated number length? #15

Open
ioleo opened this issue Feb 9, 2016 · 11 comments
Open

Generated number length? #15

ioleo opened this issue Feb 9, 2016 · 11 comments

Comments

@ioleo
Copy link

ioleo commented Feb 9, 2016

Is it possible to control the generated number length?

Eg. say I need 7-digits unique numbers, generated based on some integer eg.

  1 --> 1234567
 23 --> 7654321
100 --> 0112110

?

@mtangoo
Copy link

mtangoo commented Mar 2, 2016

I'm interested also to this. Is it possible to generate fixed length numbers or at least know the length of the number in terms of range?

@ioleo
Copy link
Author

ioleo commented Mar 2, 2016

@mtangoo I actually created my own library for this loostro/cryptomute - an implementation of Format Preserving Encryption based on Feistel Ciphers.

@jenssegers
Copy link
Owner

The maximum value is controlled by the const MAX_INT = 2147483647; value. But there is no easy way of overwriting that value at this moment.

But you could try extending the class and overwriting the MAX_INT value.

@jenssegers
Copy link
Owner

Could you also elaborate on the use case?

@mtangoo
Copy link

mtangoo commented Mar 2, 2016

Suppose you generate something like Student ID. You want all student IDs to have same length in digits despite their real IDs. Another example might be a bank account
@jenssegers

@mtangoo
Copy link

mtangoo commented Mar 2, 2016

@loostro
If I happen to have a Billion IDs will there be a collision with your library?

@ioleo
Copy link
Author

ioleo commented Mar 2, 2016

@mtangoo no, there will be none. Read on Formart Preserving Encryption

@mtangoo
Copy link

mtangoo commented Mar 2, 2016

@loostro thanks.

@EthraZa
Copy link

EthraZa commented Jul 7, 2016

You may do:

$myId = str_pad($optimusId, 7, 0, STR_PAD_LEFT);

ConnorVG pushed a commit to ConnorVG/optimus that referenced this issue Jun 5, 2017
@jonagoldman
Copy link

any updates on this?

@courtney-miles
Copy link
Contributor

PR #36 introduces flexibility around this.

Note that from what I could see, the maths for generating the integers requires a binary numbers. This means you could restrict the numbers to 65535 but not 99999.

For anyone who desperately needs more flexibility, a similar strategy is described at A practical use of multiplicative inverses which uses Modulus rather than a Bitwise And to shift the value. I found in testing that this method allows any int to be used as a max. However it also requires the use of co-prime rather than a prime. So the strategy is not compatible with Optimus.

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

6 participants