def ecpf_binhex(bstr):
“”"
Convert FROM ECPF4 1024 bit binary string TO hex string, bytewise, preserving leading zeros
parameters:
bstr (str): ECPF4 fingerprint binary string
returns:
str: hex represention of binary ECPF4 fingerprint
“”"
calculate length of hex string from length of bstr - fwiw bstr often 1024 bits and thus hlen = 256
hlen = (len(bstr) + 3) // 4
# use .format method to convert directly from binary string to hex via int - faster than iterating
return ‘{:0{}x}‘.format(int(bstr, 2), hlen)
def ecpf_hexbin(hstr):
“”"
Convert FROM ECPF4 hex string [BACK] TO binary string, preserving leading zeros
parameters:
hstr (str): ECPF4 fingerprint hex string
returns:
str: binary represention of hex ECPF4 fingerprint
“”"
calculate length of binary string from length of hstr - fwiw hstr often 256 chars and thus blen = 1024
# length of hex string - fwiw often 1024 bits
blen = len(hstr) * 4
# use .format method to convert directly from hex string to binary via int - faster than iterating
return ‘{:0{}b}’.format(int(hstr, 16), blen)
def ecpf_binhex(bstr): “”" Convert FROM ECPF4 1024 bit binary string TO hex string, bytewise, preserving leading zeros parameters: bstr (str): ECPF4 fingerprint binary string returns: str: hex represention of binary ECPF4 fingerprint “”"
calculate length of hex string from length of bstr - fwiw bstr often 1024 bits and thus hlen = 256
def ecpf_hexbin(hstr): “”" Convert FROM ECPF4 hex string [BACK] TO binary string, preserving leading zeros parameters: hstr (str): ECPF4 fingerprint hex string returns: str: binary represention of hex ECPF4 fingerprint “”"
calculate length of binary string from length of hstr - fwiw hstr often 256 chars and thus blen = 1024