Library of random related utilities, based on the ChaCha20 stream cipher
Project description
ChaCha20-Generator-Utilities - Python
Uses the ChaCha20 implementation in pycryptodome https://pycryptodome.readthedocs.io/en/latest/ as a base for various functions related to random number generation.
The actual file is chacha20_generator.py inside the folder "clcert_chachagen", but we structured it this way to make use of setup.py and make the python version a proper package.
Install package
$ pip install clcert_chachagen
Examples
import clcert_chachagen as chachagen
# Create a chacha object with a zeros seed
chacha_zero = chachagen.ChaChaGen()
# Create a chacha object with a seed (hexadecimal)
chacha = chachagen.ChaChaGen("5ee5e2327a68a9db8a78efdaa855d102ed8bf14e128e0a72ae1c9d72e5f9747e27479f21dfbfd501")
# Get a float in [0, 1)
chacha.random() # 0.47738372261817247
# Get 3 random bytes
chacha.getbytes(3) # b'\\1N'
# Get 5 random bits (an integer between 0 and 2^5 - 1)
chacha.getrandbits(5) # 9
# Get a number between [1, 100]
chacha.randint(1, 100) # 71
# Shuffle an array
chacha.shuffle([1,2,3,4]) # [4, 1, 3, 2]
# Get a single random element from an array
chacha.choice([1,2,3,4]) # 3
# Get an array of 5 elements from a given array. The elements could be repeated.
chacha.choices([1,2,3,4], 5) # [4, 3, 1, 4, 4]
# Get an array of 3 elements from a given array. The elements can't be repeated.
chacha.sample([1,2,3,4,5], 3) # [4, 5, 3]
# Reseed (essentially the same as creating an entirely new one with the new seed)
chacha.reseed("8ee5e2327a68a9db8a78efdaa855d102ed8bf14e128e0a72ae1c9d72e5f9747e27479f21dfbfd501")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
clcert_chachagen-1.1.tar.gz
(4.1 kB
view details)
Built Distribution
File details
Details for the file clcert_chachagen-1.1.tar.gz
.
File metadata
- Download URL: clcert_chachagen-1.1.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 407fedb8de38206c98b3f207860b0ee81a5ae86ede382283502ca44cdd329e6e |
|
MD5 | e3156da5ffc380594982d160cb8320ba |
|
BLAKE2b-256 | ba8b3e449da3e3f32e0a5a8cc6f278c6848cbbba741ecd1648444da5b631462b |
File details
Details for the file clcert_chachagen-1.1-py3-none-any.whl
.
File metadata
- Download URL: clcert_chachagen-1.1-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f3732ed78740c866cdf594fd71482b19c009afb48bdac7259c98ca68aee6943 |
|
MD5 | 047abb1fe6dd4ee3dad415895e42e3a1 |
|
BLAKE2b-256 | 39c2ee3c08deb8fa69767a2878c4ddd57709fae5a999f7f0a3ef14c7ef25d79b |