Skip to content

Instantly share code, notes, and snippets.

@XertroV
Created March 6, 2014 06:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save XertroV/9383437 to your computer and use it in GitHub Desktop.
Save XertroV/9383437 to your computer and use it in GitHub Desktop.
Turn any <20 bytes into a bitcoin address
#!/usr/bin/python
from hashlib import sha256
import sys
from pycoin.encoding import b2a_base58
def hashme(m):
return sha256(m).digest()
if len(sys.argv) == 1:
inputBytes = raw_input("Type your message > ")
else:
inputBytes = sys.argv[1]
print repr(inputBytes)
if len(inputBytes) > 20:
print 'error: too many bytes'
sys.exit()
while len(inputBytes) != 20:
inputBytes += '2e'.decode('hex')
inputBytes = '00'.decode('hex') + inputBytes
checksum = hashme(hashme(inputBytes))[:4]
bytesAddr = inputBytes + checksum
address = b2a_base58(bytesAddr)
print address
#print bytesAddr.encode('hex')
#print bytesAddr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment