Skip to main content

Shuffle bits in integer numbers

Project description

bit-permutation

Shuffle bits in integer numbers.

PyPI - Version codecov Documentation Status PyPI - Downloads

Synopsis

pip install bit-permutation
>>> from bit_permutation import BitShuffle

>>> bs = BitShuffle.generate_random(16)  # Permutation for lower 16 bits
>>> bs.shuffle(123)
41868
>>> bs.unshuffle(41868)
123

>>> shuffled = [bs.shuffle(x) for x in range(10)]
>>> shuffled
[42525, 42517, 9757, 9749, 42509, 42501, 9741, 9733, 34333, 34325]

>>> [bs.unshuffle(y) for y in shuffled]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Overview

The pure-Python bit-permutation package provides tools for shuffling bits in integers, including classes designed for bit permutations and inversions.

This module is primarily useful for obscuring monotonically increasing numbers, such as auto-incrementing database identifiers, which can be vulnerable to Insecure Direct Object Reference as described by OWASP. By rearranging and inverting bits within these identifiers, the sequential nature of the numbers becomes less obvious, adding a layer of security.

While this technique is an example of security through obscurity and should not replace comprehensive information hiding practices, it can still be valuable in various scenarios. The module allows to create a defined or random combination of bit permutation and inversion, resulting in a bijective transformation of a set of integers.

Disclaimer

  1. Not intended for cryptographic use: this module is not designed or intended for use in cryptography. The algorithms and functions provided do not offer the security guarantees required for cryptographic applications.

  2. Not suitable for highly loaded applications: the module is not optimized for performance in highly loaded or real-time environments. It should not be used in scenarios where performance and efficiency are critical.

  3. Not for mathematical applications: although the module provides functions for checking permutation properties, it is not intended for rigorous mathematical applications. The functionality may be useful for basic operations and educational purposes but is insufficient for advanced combinatorics or group theory studies.

Documentation

Read the full documentation at Read the docs.

The bit-permutation package provides three classes for export:

All class instances are hashable and should be treated as immutable. Instances can be compared for equality within the same class.

License

Copyright 2024 Oleh Alistratov

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

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

bit_permutation-1.0.19.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bit_permutation-1.0.19-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file bit_permutation-1.0.19.tar.gz.

File metadata

  • Download URL: bit_permutation-1.0.19.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for bit_permutation-1.0.19.tar.gz
Algorithm Hash digest
SHA256 e1d93b62b62b104da36372836585f0a96275fa6fa0bec6abf980f4902b0914a1
MD5 7c7953cb1bbe9e37740fc8e70883b400
BLAKE2b-256 f9b57cfe81d4514f3f63092f8d25e379460e7889406b7f3972422acf416af2ff

See more details on using hashes here.

File details

Details for the file bit_permutation-1.0.19-py3-none-any.whl.

File metadata

File hashes

Hashes for bit_permutation-1.0.19-py3-none-any.whl
Algorithm Hash digest
SHA256 63a91d16d460e21309c005eb7eda58578cfc66534a9c852b9620b6c8fe2c65ac
MD5 68359f1a779b62b6c58acd3b9d80ab8e
BLAKE2b-256 4909e7d61bee8891d6bc01c3d6beb508a43ecb05c633be8f677d6790fbe6da7d

See more details on using hashes here.

Supported by

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