This package implements a simple, configurable permutation on the set of 64-bit integers.
The permutation is based on a bitmask that maps each bit of the input to a bit of the output. The bitmask is expanded from a random seed using a PRNG, as described by George Marsaglia in his paper called Xorshift RNGs. The permutations are thus believed to be unpredictable, provided provided that the seed is kept secret.
Usage
Create a new Permutation instance by passing in an optional seed.
>>> fromo intperm import Permutation
>>> perm = Permutation(42)
>>> perm.map_to(37)
13750393542137160527L
>>> perm.map_from(13750393542137160527)
37
Not providing a seed will create a random permutation:
>>> perm = Permutation()
>>> perm.map_from(perm.map_to(37)) == 37
True
Use cases
Use cases may vary, but an example that I find useful is generating hard-to-guess, random-looking tokens based on IDs stored in a database. The IDs can be used together with the seed to decode the original ID, but their cardinality is the same as that of the IDs themselves. When used smartly, this can save you from having to index those tokens in the database.
Another good example is randomising IDs of private objects that are available via some sort of an API. Let’s say the user accounts on your website are accessible via the path /user/:id, where :id is the user’s ID. Someone could track the growth of your user base just by enumerating the URLs and keeping track of the status codes (e.g. 403 vs. 404).
Using this simple permutation, user IDs can be kept unpredictable, rendering these kinds of attacks practically useless.
See also
Metadata
Release files for intperm 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| intperm-1.1.1.tar.gz | 4.7 kB | Without provenance | Details |
Release files / intperm-1.1.1.tar.gz
| Download URL | intperm-1.1.1.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8b83697faea4c329ca7c49220f62ce0dd0630b33b510bb4fc9eb66dda54f128e
|
|
BLAKE2b-256 checksum How to use checksums |
c6265253912adf5aa8bad2a0a23f4552231a19d19ac98b8ad99c88184917ebe6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for intperm 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.