Skip to main content

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.

Metadata

Release files for bit-permutation 1.0.22

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bit-permutation 1.0.22
File Size Uploaded
bit_permutation-1.0.22.tar.gz 12.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bit-permutation 1.0.22
File Interpreter ABI Platform
bit_permutation-1.0.22-py3-none-any.whl Python 3 none any Details

Total release size: 26.0 kB

Release files / bit_permutation-1.0.22.tar.gz

Download URL bit_permutation-1.0.22.tar.gz
Size 12.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a750f99d5e0650b71d46f41ed97347d114950cc7d30c562cc0cd5f0326c38a51
BLAKE2b-256 checksum
How to use checksums
c4909a0ddc34306e20f48b9b919470f6b507567f33d174d8a13468c1754e1ebb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

Release files / bit_permutation-1.0.22-py3-none-any.whl

Download URL bit_permutation-1.0.22-py3-none-any.whl
Size 13.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0672f4313c045bc907961bdbeab8efe8f523b081d87375ef6bbbd0d5cb768720
BLAKE2b-256 checksum
How to use checksums
7cc47150a361e5db5656a0280b640171f081e55b6afb1166f41d640acd7d03ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.23

Release history Release notifications | RSS feed

This release

1.0.22 This release

2 release files

1.0.21

2 release files

1.0.20

2 release files

1.0.19

2 release files

1.0.16

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page