From 36b8bef11ae6c8c38a292fe78bc7108a1900087e Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Sun, 10 Apr 2016 11:41:14 +0300 Subject: [PATCH] Python3 compatibility --- ssss.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ssss.py b/ssss.py index f8ce958..2546147 100644 --- a/ssss.py +++ b/ssss.py @@ -26,7 +26,7 @@ from pygost.utils import long2bytes SECRET_LEN = 32 -POLY = 115792089237316195423570985008687907853269984665640564039457584007913129640997L +POLY = 115792089237316195423570985008687907853269984665640564039457584007913129640997 # pylint: disable=line-too-long def _lshift(x, bits): @@ -36,7 +36,7 @@ def _lshift(x, bits): def _field_mult(x, y): b = x z = b if y & 1 == 1 else 0 - for i in xrange(1, SECRET_LEN * 8): + for i in range(1, SECRET_LEN * 8): b = _lshift(b, 1) if (b >> (SECRET_LEN * 8)) & 1 == 1: b ^= POLY @@ -47,7 +47,7 @@ def _field_mult(x, y): def _horner(t, x, coef): y = coef[t - 1] - for i in xrange(t - 1, 0, -1): + for i in range(t - 1, 0, -1): y = _field_mult(y, x) y ^= coef[i - 1] return y @@ -69,7 +69,7 @@ def _field_invert(x): def _calculate_li0(t, x, i): li0 = 1 - for j in xrange(t): + for j in range(t): if j == i: continue li0 = _field_mult(li0, x[j]) @@ -92,10 +92,10 @@ def split(secret, n, t): coef = [bytes2long(secret[::-1])] if n < 0 or t < 0 or n < t or not secret: raise ValueError("Invalid parameters specified") - for i in xrange(1, t): + for i in range(1, t): coef.append(bytes2long(urandom(SECRET_LEN))) out = [] - for i in xrange(1, n + 1): + for i in range(1, n + 1): out.append((i, long2bytes(_horner(t, i, coef))[::-1])) return out @@ -116,9 +116,9 @@ def combine(t, parts): raise ValueError("Invalid parameters specified") if len(parts) != len(set(s[1] for s in parts)): raise ValueError("Equal parts found") - x, y = zip(*[(s[0], bytes2long(s[1][::-1])) for s in parts]) + x, y = list(zip(*[(s[0], bytes2long(s[1][::-1])) for s in parts])) sec = 0 - for i in xrange(t): + for i in range(t): li0 = _calculate_li0(t, x, i) li0si = _field_mult(li0, y[i]) sec = sec ^ li0si -- 2.44.0