diff --git a/src/condensed.py b/src/condensed.py --- a/src/condensed.py +++ b/src/condensed.py @@ -30,7 +30,7 @@ L[1] = 0 inv = [E[255-L[i]] if i!=0 else None for i in range(256)] # multiplicative inverse -def getConstantCoef(*points): +def get_constant_coef(*points): """Compute constant polynomial coefficient given the points. See https://en.wikipedia.org/wiki/Shamir's_Secret_Sharing#Computationally_Efficient_Approach""" @@ -55,26 +55,26 @@ import binascii class SException(Exception): pass -def reconstructRaw(*shares): +def reconstruct_raw(*shares): """Tries to recover the secret from its shares. :param shares: ((i, (bytes) share), ...) :return: (bytes) reconstructed secret. Too few shares returns garbage.""" - secretLen = len(shares[0][1]) - res = [None]*secretLen - for i in range(secretLen): + secret_len = len(shares[0][1]) + res = [None]*secret_len + for i in range(secret_len): points = [(x, s[i]) for (x, s) in shares] - res[i] = (getConstantCoef(*points)) + res[i] = (get_constant_coef(*points)) return bytes(res) def reconstruct(*shares): - """Wraps reconstructRaw. + """Wraps reconstruct_raw. :param shares: ((str) share, ...) :return: (str) reconstructed secret. Too few shares returns garbage.""" - bs = reconstructRaw(*(decode(s) for s in shares)) + bs = reconstruct_raw(*(decode(s) for s in shares)) try: return bs.decode(encoding="utf-8") except UnicodeDecodeError: @@ -83,13 +83,13 @@ def reconstruct(*shares): def decode(share): try: - (i, _, shareStr) = share.partition(".") + (i, _, share_str) = share.partition(".") i = int(i) if not 1<=i<=255: raise SException("Malformed share: Failed 1<=k<=255, k={0}".format(i)) - shareBytes = base64.b32decode(shareStr) - return (i, shareBytes) + share_bytes = base64.b32decode(share_str) + return (i, share_bytes) except (ValueError, binascii.Error): raise SException('Malformed share: share="{0}"'.format(share))