Skip to content

Instantly share code, notes, and snippets.

@RyanKung
Last active September 15, 2017 12:43
Show Gist options
  • Save RyanKung/974c0442f02c64b6388fb2eef42d9c0d to your computer and use it in GitHub Desktop.
Save RyanKung/974c0442f02c64b6388fb2eef42d9c0d to your computer and use it in GitHub Desktop.
from hashlib import sha256
import random
import base58
import re
import sys
def gen_private_key(version=128, compress=1):
max = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
key = random.randint(1, max)
private_key = bytes([version]) + key.to_bytes(
32, byteorder='big') + bytes([compress])
auth = sha256(sha256(private_key).digest()).digest()[:4]
res = private_key + auth
assert len(res) == 1 + 32 + 1 + 4
return base58.b58encode(res)
def calcu(p):
patten = re.compile(p)
time = 0
while 1:
time = time + 1
pk = gen_private_key()
print('trying %s time: %s' % (str(time), pk))
if patten.match(str(pk)):
return pk
if __name__ == '__main__':
print(calcu(sys.argv[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment