-
-
Save RickyCook/4b62bb04f3cd965398103db13dbe92d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GROUP_BITS = 31 | |
PRIME = 7 | |
def ddd(index): | |
""" | |
Examples: | |
>>> ddd(111) | |
'00*00*0001***0*0*001****0**0**' | |
""" | |
bitstring = bin(int(index))[2:].zfill(GROUP_BITS - 1) | |
return encode(bitstring, GROUP_BITS, PRIME) | |
def encode(y, s, p): | |
l = ["*"] * (s - 1) | |
i = 1 | |
tmp = y[0] | |
for t in range(s): | |
l[i - 1] = tmp | |
tmp = y[i - 1] | |
i = i * p % s | |
return ''.join(l) | |
def inv(s, p): | |
for x in range(s): | |
if x * p % s == 1: | |
return x | |
return None | |
def decode(y, s, p): | |
return encode(y, s, inv(s, p)) | |
def arr2int(arr): | |
return int(''.join(arr), 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment