Skip to main content

A small library for obfuscating integer values to key strings using a set length and alphabet.

Project description

Obfuskey

pypi license coverage build

Taking lessons learned from supporting BaseHash over the years, it was obvious that it could be optimized, thus Obfuskey was born. BaseHash had some misconceptions, mainly that consumers thought it was a crypto library due to the word "hash". Since a hashes are generally irreversible, this new project was born to clearly convey what it is used for.

Obfuskey was a way to both modernize and simplify BaseHash, while keeping the same functionality. Obfuskey generates obfuscated keys out of integer values that have a uniform length using a specified alphabet. It was built solely for Python 3.6 and up. There are no guarantees that it will work for lower versions. If you need this for a lower version, please use BaseHash.

When generating keys, the combination of key length and alphabet used will determine the maximum value it can obfuscate, len(alphabet) ** key_length - 1.

Usage

To use Obfuskey, you can use one of the available alphabets, or provide your own. You can also provide your own multiplier, or leave it blank to use the built-in prime generator.

from obfuskey import Obfuskey, alphabets

obfuscator = Obfuskey(alphabets.BASE36, key_length=8)

key = obfuscator.get_key(1234567890)  # FWQ8H52I
value = obfuscator.get_value('FWQ8H52I')  # 1234567890

To provide a custom multiplier, or if you to provide the prime generated from a previous instance, you can pass it in with multiplier=. This value has to be an odd integer.

from obfuskey import Obfuskey, alphabets

obfuscator = Obfuskey(alphabets.BASE62)
key = obfuscator.get_key(12345)  # d2Aasl

obfuscator = Obfuskey(alphabets.BASE62, multiplier=46485)
key = obfuscator.get_key(12345)  # 0cpqVJ

If you wish to generate a prime not within the golden prime set, you can overwrite the multiplier with set_prime_multiplier.

from obfuskey import Obfuskey, alphabets

obfuscator = Obfuskey(alphabets.BASE62, key_length=2)
key = obfuscator.get_key(123)  # 3f

obfuscator.set_prime_multiplier(1.75)
key = obfuscator.get_key(123)  # RP

There are predefined alphabets that you can use, but Obfuskey allows you to specify a custom one during instantiation.

from obfuskey import Obfuskey

obfuscator = Obfuskey('012345abcdef')
key = obfuscator.get_key(123) #022d43

Extras

If you need to obfuscate integers that are larger than 512-bit, you will need to also have gmp2 installed.

$ pip install gmpy2

OR

poetry install -E gmpy2

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

obfuskey-0.1.3.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

obfuskey-0.1.3-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file obfuskey-0.1.3.tar.gz.

File metadata

  • Download URL: obfuskey-0.1.3.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.8.12 Linux/5.11.0-1027-azure

File hashes

Hashes for obfuskey-0.1.3.tar.gz
Algorithm Hash digest
SHA256 92fb8083d6a64c040bdac70fd181e83321ac9589d2e2c56e425c03743c4bf344
MD5 0ba5658c4bc2609b4901ee19ecd76e9d
BLAKE2b-256 687b90ada6353c2f3e42db85193dc4e9918751ddb2b553503927a6a02d704628

See more details on using hashes here.

File details

Details for the file obfuskey-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: obfuskey-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.11 CPython/3.8.12 Linux/5.11.0-1027-azure

File hashes

Hashes for obfuskey-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ff43cae31b641505114daa4770aa1ead55227c2926bfdd469ef58dc548aa8420
MD5 8a362f98f68176202ff17b7f058ffe62
BLAKE2b-256 91ad4472e1cbf08f071f0c0a99a171f529441744f8b351101243419d1ac39bec

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page