Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Python script to output Bitfi key material compatible with `brainflayer -x -t priv`.
#!/usr/bin/env python
# This script accepts salt,passphrases pairs on STDIN seperated by a tab.
# Specify the coin symbol and indexes to generate via command line args.
# Appears to work fine with Bitcoin, Litecoin and Ethereum, probably works
# with many other coins as well.
# Don't participate in Bitfi's pay-to-play Bounty - it's a sham.
import sys
import hmac
import hashlib
import scrypt
from pybitcointools import *
def ci(s):
acc = ""
for c in s.upper():
acc += str(ord(c)-64)
return int(acc)
def coinkey(password, salt, coin):
k_par = scrypt.hash(password, salt, N=32768, p=4, r=8, buflen=64)
c_par = hashlib.sha256(salt).digest()
param =, k_par, hashlib.sha512).digest()
(msk, mcc) = (param[0:32], param[32:64])
master_key = bip32_serialize((PRIVATE, 0, b'\x00'*4, 0, mcc, msk+b'\x01'))
return bip32_ckd(master_key, ci(coin) | 0x80000000)
def subkey(key, n):
sub_key = bip32_ckd(key, n)
return bip32_extract_key(sub_key)[0:64]
if __name__ == "__main__":
coin = 'btc'
n_start = 0
n_end = 10
if len(sys.argv) > 1:
coin = sys.argv[1]
if len(sys.argv) > 2:
n_start = int(sys.argv[2])
n_end = n_start+1
if len(sys.argv) > 3:
n_end = int(sys.argv[3])+1
for line in sys.stdin:
line = line.rstrip("\r\n")
(salt, password) = line.split("\t")
coin_key = coinkey(password, salt, coin)
for n in xrange(n_start, n_end):
print "%s:%s:%d:%s:%s" % (subkey(coin_key, n), coin, n, salt, password)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.