Created
July 17, 2019 17:16
-
-
Save ymgve/fa50dc807d83b6011346fa0f3bcfba7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib, sys | |
b58ab = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" | |
def b58csum(s): | |
return hashlib.sha256(hashlib.sha256(s).digest()).digest()[0:4] | |
def b58decode(s, checksum=True): | |
idx = 0 | |
while s[idx] == "1": | |
idx += 1 | |
n = 0 | |
for c in s[idx:]: | |
n = n * 58 + b58ab.index(c) | |
res = long2byte(n) | |
res = idx * "\x00" + res | |
if checksum: | |
res, cs = res[:-4], res[-4:] | |
assert cs == b58csum(res), "base58 checksum failed" | |
return res | |
def b58encode(s, checksum=True): | |
if checksum: | |
s += b58csum(s) | |
idx = 0 | |
while s[idx] == "\x00": | |
idx += 1 | |
n = byte2long(s) | |
res = "" | |
while n > 0: | |
res = b58ab[n % 58] + res | |
n /= 58 | |
return "1" * idx + res | |
def byte2long(s): | |
res = 0 | |
for c in s: | |
res = (res << 8) | ord(c) | |
return res | |
def long2byte(n, sz=None): | |
res = "" | |
while n > 0: | |
res = chr(n & 0xff) + res | |
n >>= 8 | |
if sz is not None: | |
res = res.rjust(sz, "\x00") | |
return res | |
priv = b58decode(sys.argv[1]) | |
print "BTC private key", sys.argv[1] | |
print "BTC raw private key", priv.encode("hex") | |
print "BVX private key", b58encode("\xca" + priv[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment