add dcd.bit.Bitfield and related goodies
This commit is contained in:
parent
d72659088f
commit
10830999be
3 changed files with 73 additions and 28 deletions
42
dcd/aux.py
42
dcd/aux.py
|
@ -18,6 +18,20 @@ def flatten_dict(root, glue=" ", prefix=[]):
|
|||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
def clamp(A, low, high):
|
||||
"""
|
||||
Clamps integer A to <low; high>
|
||||
"""
|
||||
|
||||
if A < low:
|
||||
return low
|
||||
elif A > high:
|
||||
return high
|
||||
else:
|
||||
return A
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
import random
|
||||
|
||||
PASSPHRASE_VOWELS = "aeiuAEU"
|
||||
|
@ -50,34 +64,6 @@ def hash_password(p, hexdigest=True):
|
|||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
def raw_to_hex(raw, separator=" "):
|
||||
"""
|
||||
Converts a bytearray (or bytes) into its textual hexadecimal representation.
|
||||
"""
|
||||
|
||||
output = []
|
||||
|
||||
for o in raw:
|
||||
output.append(hex(o)[2:].zfill(2))
|
||||
|
||||
return separator.join(output)
|
||||
|
||||
def hex_to_raw(text, separator=" "):
|
||||
"""
|
||||
Converts a hexadecimal representation of a byte array into a bytearray.
|
||||
"""
|
||||
|
||||
output = []
|
||||
|
||||
text = text.replace(separator, "")
|
||||
|
||||
for i in range(len(text)//2):
|
||||
output.append(int(text[2*i:2*i+2], 16))
|
||||
|
||||
return bytearray(output)
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
class DeleteOverlay:
|
||||
pass
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue