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

Control Optimus output size #9

Open
PedroEFLourenco opened this issue Jun 7, 2022 · 10 comments
Open

Control Optimus output size #9

PedroEFLourenco opened this issue Jun 7, 2022 · 10 comments

Comments

@PedroEFLourenco
Copy link

Is it possible to limit the digit number of the optimus obfuscation output?
Like, generate obfuscated ids with up to 7digits.

I understand this would limit the number of possible ids, but it would still be helpful for my use-case.

@pjebs
Copy link
Owner

pjebs commented Jun 9, 2022

Try and modify MAX_INT to 2^N.

@PedroEFLourenco
Copy link
Author

PedroEFLourenco commented Jun 9, 2022

I don't really know what that means in practical terms, my math is pretty rusty.
That being said, I changed it to the upper bound of numbers I wanted (9999999), and ran the example like this (ignore the package names, its just because I copied the code to some other project I have for testing stuff):

mod_inverse := optimus_go.ModInverse(4161499)
o := optimus_go.New(4161499, mod_inverse, 493244)

new_id := o.Encode(15) 
fmt.Println(new_id)

orig_id := o.Decode(new_id)
fmt.Println(orig_id)

Which didn't really work, since it gave this output:

10457833
8951311

So either I am doing something wrong, or it didn't work as expected.

@pjebs
Copy link
Owner

pjebs commented Jun 9, 2022

It has to be a power of 2.

@PedroEFLourenco
Copy link
Author

Thank you for the reply.
Tried it now with the same values but with MAX_INT set to the highest power of 2 that has 7 or less (8881852), but it still didn't work as expected

The results were:

8881852
0

@pjebs
Copy link
Owner

pjebs commented Jun 9, 2022

Can you show me on go playground

@PedroEFLourenco
Copy link
Author

Yes, sure. Here it is: https://go.dev/play/p/op2AXGK8_xm

@pjebs
Copy link
Owner

pjebs commented Jun 9, 2022

I mean your code

@PedroEFLourenco
Copy link
Author

Yes, the code is in the main function inside the go playground I linked above.

@pjebs
Copy link
Owner

pjebs commented Jun 10, 2022

Maybe the mod function assumes int64

@hzmsrv
Copy link

hzmsrv commented Jun 29, 2023

how to support int64?

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