Solved TestAddresses's test_privtopub testcase issue

This commit is contained in:
jai.s 2020-10-05 18:58:03 +05:30
parent 57d22a5cd6
commit ef3e496fbd
No known key found for this signature in database
GPG Key ID: 360CFA25EFC67D12
2 changed files with 5 additions and 10 deletions

View File

@ -16,7 +16,7 @@ def inv(a, n):
lm, hm = 1, 0 lm, hm = 1, 0
low, high = a % n, n low, high = a % n, n
while low > 1: while low > 1:
r = high / low r = high // low
nm, new = hm - lm * r, high - low * r nm, new = hm - lm * r, high - low * r
lm, low, hm, high = nm, new, lm, low lm, low, hm, high = nm, new, lm, low
return lm % n return lm % n
@ -96,12 +96,7 @@ def base10_double(a):
return None return None
m = int((3 * a[0] * a[0] + A) * inv(2 * a[1], P)) % P m = int((3 * a[0] * a[0] + A) * inv(2 * a[1], P)) % P
x = int(m * m - 2 * a[0]) % P x = int(m * m - 2 * a[0]) % P
y = int(m * (a[0] - x) - a[1]) % P y = int(m * (a[0] - x) - a[1]) % P
# print('++++++++++++++++++++++++++++++++')
# print('inside the base10_double')
# print('the value of x -{}'.format(x))
# print('the value of y -{}'.format(y))
# print('++++++++++++++++++++++++++++++++')
return (x, y) return (x, y)
def base10_multiply(a, n): def base10_multiply(a, n):
@ -111,9 +106,9 @@ def base10_multiply(a, n):
if n == 1: if n == 1:
return a return a
if (n % 2) == 0: if (n % 2) == 0:
return base10_double(base10_multiply(a, n /2)) return base10_double(base10_multiply(a, n //2))
if (n % 2) == 1: if (n % 2) == 1:
return base10_add(base10_double(base10_multiply(a, n /2)), a) return base10_add(base10_double(base10_multiply(a, n //2)), a)
return None return None

View File

@ -79,7 +79,7 @@ class TestAddresses(unittest.TestCase):
hexlify(sample_pubsigningkey) hexlify(sample_pubsigningkey)
) )
self.assertEqual( self.assertEqual(
arithmetic.privtopub(sample_privateencryptionkey), arithmetic.privtopub(sample_privateencryptionkey.encode()),
hexlify(sample_pubencryptionkey) hexlify(sample_pubencryptionkey)
) )