From 6c0a231a29bddc99338426be185e8622c0c907d3 Mon Sep 17 00:00:00 2001 From: Jonathan Warren Date: Tue, 26 Feb 2013 16:02:38 -0500 Subject: [PATCH] Fix to Bitcoin-related functionality in arithmetic.py (thanks to Github user fcicq) --- pyelliptic/arithmetic.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pyelliptic/arithmetic.py b/pyelliptic/arithmetic.py index f54359ba..1eec381a 100644 --- a/pyelliptic/arithmetic.py +++ b/pyelliptic/arithmetic.py @@ -70,7 +70,7 @@ def base10_multiply(a,n): if (n%2) == 0: return base10_double(base10_multiply(a,n/2)) if (n%2) == 1: return base10_add(base10_double(base10_multiply(a,n/2)),a) -def hex_to_point(h): return (decode(h[2:34],16),decode(h[34:],16)) +def hex_to_point(h): return (decode(h[2:66],16),decode(h[66:],16)) def point_to_hex(p): return '04'+encode(p[0],16,64)+encode(p[1],16,64) @@ -86,9 +86,11 @@ def add(p1,p2): else: return point_to_hex(base10_add(hex_to_point(p1),hex_to_point(p2))) -def hash160(string): +def hash_160(string): intermed = hashlib.sha256(string).digest() - return hashlib.new('ripemd160').update(intermed).digest() + ripemd160 = hashlib.new('ripemd160') + ripemd160.update(intermed) + return ripemd160.digest() def dbl_sha256(string): return hashlib.sha256(hashlib.sha256(string).digest()).digest() @@ -99,5 +101,6 @@ def bin_to_b58check(inp): checksum = dbl_sha256(inp_fmtd)[:4] return '1' * leadingzbytes + changebase(inp_fmtd+checksum,256,58) +#Convert a public key (in hex) to a Bitcoin address def pubkey_to_address(pubkey): return bin_to_b58check(hash_160(changebase(pubkey,16,256)))