bnlucas / obfuskey

Reversible integer obfuscation in Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

About the integers that are larger than 512-bit

johnny-kc-wu opened this issue · comments

commented

Hi,
I have tried to input uuid4().int as the integers for get_key(), and even though gmpy2 has been installed, I still get MaximumValueError. Sould I import gmpy2 and use any of its methods/functions in my code?

The following is my code:

from obfuskey import Obfuskey, alphabets
from uuid import uuid4

def get_short_id(uuid_int: int) -> str:
    obf = Obfuskey(alphabets.BASE62, key_length=11)
    return obf.get_key(uuid_int)

if __name__ == "__main__":
    get_short_id(uuid4().int)

Thanks!

Hello! uuid4().int produces a 128-bit int, which the setup you have would not support.

The maximum value is len(alphabet) ** key_length - 1, which is 62 ** 11 - 1 = 52036560683837093887

The int value of the uuid is much larger than this. In order to support a 128-bit int using BASE62, your key length has to be a minimum of 22.

62 ** 22 - 1 = 2707803647802660400290261537185326956543

Gmpy2 is only required when the values you’re working with are 512-bit or greater. If you do need that, simply installing gmpy2 will get you up and running, no additional methods have to be called. This is all handled internally.