Fix to Bitcoin-related functionality in arithmetic.py (thanks to Github user fcicq)
This commit is contained in:
parent
3d0bdeeb9d
commit
6c0a231a29
|
@ -70,7 +70,7 @@ def base10_multiply(a,n):
|
||||||
if (n%2) == 0: return base10_double(base10_multiply(a,n/2))
|
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)
|
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)
|
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:
|
else:
|
||||||
return point_to_hex(base10_add(hex_to_point(p1),hex_to_point(p2)))
|
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()
|
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):
|
def dbl_sha256(string):
|
||||||
return hashlib.sha256(hashlib.sha256(string).digest()).digest()
|
return hashlib.sha256(hashlib.sha256(string).digest()).digest()
|
||||||
|
@ -99,5 +101,6 @@ def bin_to_b58check(inp):
|
||||||
checksum = dbl_sha256(inp_fmtd)[:4]
|
checksum = dbl_sha256(inp_fmtd)[:4]
|
||||||
return '1' * leadingzbytes + changebase(inp_fmtd+checksum,256,58)
|
return '1' * leadingzbytes + changebase(inp_fmtd+checksum,256,58)
|
||||||
|
|
||||||
|
#Convert a public key (in hex) to a Bitcoin address
|
||||||
def pubkey_to_address(pubkey):
|
def pubkey_to_address(pubkey):
|
||||||
return bin_to_b58check(hash_160(changebase(pubkey,16,256)))
|
return bin_to_b58check(hash_160(changebase(pubkey,16,256)))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user