Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ECFP4 representation ongoing development #29

Open
ipendlet opened this issue May 28, 2019 · 1 comment
Open

ECFP4 representation ongoing development #29

ipendlet opened this issue May 28, 2019 · 1 comment
Assignees

Comments

@ipendlet
Copy link
Member

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)

@ipendlet
Copy link
Member Author

See attached

ecfp4_hex_io.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants