Nonces generator for cryptographic purposes
Project description
nonces
A nonces generator based on a given size, a counter size, an optional seed and an optional byte order for the counter.
Installation
pip install nonces
Usage
from nonces import Nonce, Nonces
# To generate a new Nonces instance to generate nonces
# of 8 bytes, with a 4 bytes counter ->
nonces = Nonces(size=8, counter_size=4)
# Get the current nonce ->
nonce = nonces.nonce
new_nonce = bytes(nonce)
assert nonce == new_nonce
# Update the counter on default increment
nonces.update()
# Modify the counter to a given counter number
nonces.set_counter(10)
# Check counter value
nonces.counter
# Check counter bytes
nonces.counter_bytes
# Set it to the max counter number:
nonces.set_counter(nonces.max_counter)
# If you try to run nonces.update() at this point an OverFlowError
# as no more counters are available
nonces.update()
# Generate a new nonce of 16 bytes with 12 bytes from a given seed
#and a 4 bytes counter as little endian (counter + nonce)
seed = Nonce.random(12)
# Nonce.random(12) returns a 12 bytes random nonce
nonces = Nonces(
size=16,
counter_size=4,
seed=seed,
order='little'
)
for i in range(10):
nonces.update()
# Check seed value
nonces_seed = nonces.seed_bytes
assert seed == nonces_seed
# Change the increment value
nonces.increment = 255
for i in range(10):
nonces.update()
# Get nonce value encoded in hex
nonce = nonces.nonce
nonce_hex = nonce.hex()
# Load a hex encoded nonce
new_nonce = Nonce.fromhex(nonce_hex)
assert nonce == new_nonce
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
nonces-1.0.0.tar.gz
(8.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nonces-1.0.0.tar.gz.
File metadata
- Download URL: nonces-1.0.0.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96ce73c86de8a507226f94bebd7edb944371cdfb54315d339c34372bf8ca6595
|
|
| MD5 |
e3ef4c999d7f8437db4914a49813b710
|
|
| BLAKE2b-256 |
53e71693f873aef53ea63e3da0683168150209f4a076bea247c63c714c093771
|
File details
Details for the file nonces-1.0.0-py3-none-any.whl.
File metadata
- Download URL: nonces-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a79873d17d20810bf369c743f65f6328024a0e14773acdb693020dcaff770045
|
|
| MD5 |
6662b1103a1e23a8adb129fb02bac4e8
|
|
| BLAKE2b-256 |
e73896659ead2b76965485da65ff24d54beba18247015c1831cb5bc3ade0e537
|