Skip to content

Instantly share code, notes, and snippets.

from ec_point_operation import curve, scalar_multiply
from meta import int_to_varint, address_to_public_key_hash, build_locking_script, deserialize_signature, serialize_signature, serialize_public_key
from crypto import double_sha256
from sign import verify_signature, sign
from collections import namedtuple
from binascii import unhexlify, hexlify
VERSION = 0x01.to_bytes(4, 'little')
SEQUENCE = 0xffffffff.to_bytes(4, byteorder='little')
LOCK_TIME = 0x00.to_bytes(4, byteorder='little')
from ec_point_operation import curve, add, scalar_multiply
from modular_inverse import modular_multiplicative_inverse
from crypto import double_sha256
import random
def hash_to_int(message: bytes) -> int:
"""Calculate the bitcoin double-sha256 hash of the message, return as an integer"""
h = double_sha256(message)
return int.from_bytes(h, byteorder='big')
import collections
from modular_inverse import modular_multiplicative_inverse
EllipticCurve = collections.namedtuple('EllipticCurve', 'name p a b g n h')
curve = EllipticCurve(
def extended_euclid_gcd(a: int, b: int) -> list:
Returns [gcd(a, b), x, y] where ax + by = gcd(a, b)
s, old_s = 0, 1
t, old_t = 1, 0
r, old_r = b, a
while r != 0:
quotient = old_r // r
old_r, r = r, old_r - quotient * r
import hashlib
from binascii import hexlify
def sha256(payload: bytes) -> bytes:
return hashlib.sha256(payload).digest()
def double_sha256(payload: bytes) -> bytes:
return sha256(sha256(payload))
from ec_point_operation import curve
from crypto import ripemd160_sha256, b58check_encode, b58check_decode
from binascii import hexlify
def int_to_varint(value: int) -> bytes:
if value <= 0xfc:
return value.to_bytes(1, 'little')
elif value <= 0xffff:
return b'\xfd' + value.to_bytes(2, 'little')
gitzhou /
Created Jun 8, 2020
Get local time of specific timezone from UTC
from pytz import timezone
from datetime import datetime
now = timezone('Asia/Shanghai').fromutc(datetime.utcnow())
print(now.strftime('%Y-%m-%d %H:%M:%S'))
from bitsv.base58 import b58encode, b58decode
from bitsv.crypto import ECPrivateKey, sha256, hash160
from binascii import hexlify
# pip install bitsv
View pbkdf2-nodejs
const crypto = require('crypto');
const hash = 'sha512'
const round = 2048
const seed_bytes = 64
var mnemonic = 'furnace tunnel buyer merry feature stamp brown client fine stomach company blossom'
var passphrase = ''
View hex-to-oct.cpp
// main.cpp
// hex-to-oct
// Created by aaron67 on 2017/1/23.
// Copyright © 2017年 aaron67. All rights reserved.
#include <iostream>
#include <iomanip>
You can’t perform that action at this time.