Skip to content

Instantly share code, notes, and snippets.

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
@gitzhou
gitzhou / crypto.py
Last active February 6, 2022 04:06
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))
@gitzhou
gitzhou / meta.py
Last active October 19, 2020 03:07
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
gitzhou / test.py
Created June 8, 2020 19:02
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
#
# https://aaron67.cc/2019/01/04/bitcoin-address/
#
print()
// https://github.com/crypto-browserify/pbkdf2
//
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 = ''
//
// main.cpp
// hex-to-oct
//
// Created by aaron67 on 2017/1/23.
// Copyright © 2017年 aaron67. All rights reserved.
//
#include <iostream>
#include <iomanip>
//
// main.cpp
// hex-to-oct
//
// Created by aaron67 on 2017/1/23.
// Copyright © 2017年 aaron67. All rights reserved.
//
#include <iostream>
#include <string>
@gitzhou
gitzhou / Preferences.sublime-settings
Last active March 14, 2017 16:13
My Sublime Text Settings
{
"auto_complete": true,
"auto_complete_commit_on_tab": true,
// 在选中区域搜索
"auto_find_in_selection": true,
"bold_folder_labels": true,
"color_scheme": "Packages/Color Scheme - Default/Monokai Bright.tmTheme",
"create_window_at_startup": false,
"draw_white_space": "all",
"highlight_line": true,
@gitzhou
gitzhou / two-eggs-problem.cpp
Created November 25, 2015 15:33
Problem of Two Eggs
//
// main.cpp
// two-eggs-problem
//
// Created by aaron67 on 15/2/12.
// Copyright (c) 2015年 aaron67. All rights reserved.
//
// 参考:http://ppwwyyxx.com/2013/Problem-of-Two-Eggs/
//
// 题目描述: