Skip to content

Instantly share code, notes, and snippets.

@migeyel
Last active September 8, 2019 18:22
Show Gist options
  • Save migeyel/a4e2a958c8ddce8126d6cf011233e38a to your computer and use it in GitHub Desktop.
Save migeyel/a4e2a958c8ddce8126d6cf011233e38a to your computer and use it in GitHub Desktop.
Some Krist Proof-of-Concept Algorithms
# Proof of Concept Vanity Miner using hash chains
# Requires only 1 hash function per address check
from hashlib import sha256
from os import urandom
from time import clock
address_byte_lookup = "0000000111111122222223333333444444455555556666666777777788888889999999aaaaaaabbbbbbbcccccccdddddddeeeeeeefffffffggggggghhhhhhhiiiiiiijjjjjjjkkkkkkklllllllmmmmmmmnnnnnnnooooooopppppppqqqqqqqrrrrrrrssssssstttttttuuuuuuuvvvvvvvwwwwwwwxxxxxxxyyyyyyyzzzzzzzeeee"
# Shifts a hash chain by 1
# Such that new_hash_chain[i] = hash_chain[i + 1] for all i
# Calls sha256 1 times
def shift_chain(hash_chain):
hash_chain.pop(0)
s = hash_chain[-1]
h = sha256(s.hex().encode()).digest()
hash_chain.append(h)
# Makes a v2 address from a hash chain
# Calls sha256 0 times
# hash_chain[0].hex() is the address' private key
def h_makev2address(hash_chain):
chain_index = 0
protein = []
chain_index += 2
n = 0
link = 0
v2 = "k"
for i in range(9):
protein.append(hash_chain[chain_index][0])
chain_index += 2
while n < 9:
link = hash_chain[chain_index][n] % 9
if protein[link] != None:
v2 += address_byte_lookup[protein[link]]
protein[link] = None
n += 1
else:
chain_index += 1
return v2
# Build a hash chain with length 200 using urandom entropy
# hash_chain[i + 1] = sha256(hash_chain[i].hex())
hash_chain = []
hash_chain.append(urandom(32))
for i in range(200):
s = hash_chain[-1]
h = sha256(s.hex().encode()).digest()
hash_chain.append(h)
print("PG's PoC Vanity Miner")
prefix = input("Prefix to mine: ")
address_count = 0
t0 = clock()
address = h_makev2address(hash_chain)
while not address.startswith("k" + prefix):
shift_chain(hash_chain)
address = h_makev2address(hash_chain)
if address_count % 100000 == 0:
print(int(address_count / (clock() - t0)), "A/s")
address_count += 1
print(hash_chain[0].hex(), address)
print("Found in", int(clock() - t0), "seconds")
# Proof of Concept Cracker for kristwallet's "local vault" feature
from hashlib import sha256
address_byte_lookup = [48, 48, 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 49, 49, 50, 50, 50, 50, 50, 50, 50, 51, 51, 51, 51, 51, 51, 51, 52, 52, 52, 52, 52, 52, 52, 53, 53, 53, 53, 53, 53, 53, 54, 54, 54, 54, 54, 54, 54, 55, 55, 55, 55, 55, 55, 55, 56, 56, 56, 56, 56, 56, 56, 57, 57, 57, 57, 57, 57, 57, 97, 97, 97, 97, 97, 97, 97, 98, 98, 98, 98, 98, 98, 98, 99, 99, 99, 99, 99, 99, 99, 100, 100, 100, 100, 100, 100, 100, 101, 101, 101, 101, 101, 101, 101, 102, 102, 102, 102, 102, 102, 102, 103, 103, 103, 103, 103, 103, 103, 104, 104, 104, 104, 104, 104, 104, 105, 105, 105, 105, 105, 105, 105, 106, 106, 106, 106, 106, 106, 106, 107, 107, 107, 107, 107, 107, 107, 108, 108, 108, 108, 108, 108, 108, 109, 109, 109, 109, 109, 109, 109, 110, 110, 110, 110, 110, 110, 110, 111, 111, 111, 111, 111, 111, 111, 112, 112, 112, 112, 112, 112, 112, 113, 113, 113, 113, 113, 113, 113, 114, 114, 114, 114, 114, 114, 114, 115, 115, 115, 115, 115, 115, 115, 116, 116, 116, 116, 116, 116, 116, 117, 117, 117, 117, 117, 117, 117, 118, 118, 118, 118, 118, 118, 118, 119, 119, 119, 119, 119, 119, 119, 120, 120, 120, 120, 120, 120, 120, 121, 121, 121, 121, 121, 121, 121, 122, 122, 122, 122, 122, 122, 122, 101, 101, 101, 101]
def sha256_hex(d):
return bytes(sha256(d).hexdigest(), "utf-8")
def makev2address(key):
protein = [b""] * 9
stick = sha256_hex(sha256_hex(key))
link = 0
v2 = "k"
for n in range(9):
protein[n] = stick[0:2]
stick = sha256_hex(sha256_hex(stick))
n += 1
n = 0
while n < 9:
link = int(stick[2*n:2+2*n], base=16) % 9
if protein[link] != b"":
v2 += chr(address_byte_lookup[int(protein[link], base=16)])
protein[link] = b""
n += 1
else:
stick = sha256_hex(stick)
return v2
# ComputerCraft's math.random function
class Random():
def __init__(self):
self.seed = 0
def setSeed(self, s):
self.seed = (s ^ 0x5DEECE66D) & ((1 << 48) - 1)
def next(self, bits):
self.seed = (self.seed * 0x5DEECE66D + 0xB) & ((1 << 48) - 1)
return (self.seed >> (48 - bits))
def nextInt(self, n):
if ((n & -n) == n):
return ((n * self.next(31)) >> 31)
bits = self.next(31)
val = bits % n
while (bits - val + (n - 1) < 0):
bits = self.next(31)
val = bits % n
return val
def random(self, min_, max_):
return min_ + self.nextInt(max_ + 1 - min_)
rand = Random()
# Finds the resulting private key given the time in an os.time() call
def time_to_pkey(time):
time /= 1000
rand.setSeed(int(time))
hval = rand.random(1, 1000000)
h = sha256((str(hval) + str(time)).encode()).hexdigest()
return h
target = input("Vault address to crack: ")
# Brute forces through all possible os.time() return values and pkeys to find the address
found = False
for i in range(23999):
pkey = time_to_pkey(i)
address = makev2address(pkey.encode())
if address == target:
print("Found key:", pkey)
found = True
break
if not found:
print("No keys found")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment