Skip to content

Instantly share code, notes, and snippets.

@dooglus
dooglus / public.py
Created August 13, 2016 20:45
create Bitcoin public key from private key
#! /usr/bin/env python
class Point(object):
def __init__(self, _x, _y, _order = None): self.x, self.y, self.order = _x, _y, _order
def calc(self, top, bottom, other_x):
l = (top * inverse_mod(bottom)) % p
x3 = (l * l - self.x - other_x) % p
return Point(x3, (l * (self.x - x3) - self.y) % p)
@dooglus
dooglus / coinswap-design.md
Last active February 27, 2021 21:35 — forked from chris-belcher/coinswap-design.md
Design for a CoinSwap Implementation for Massively Improving Bitcoin Privacy and Fungibility

Design for a CoinSwap Implementation for Massively Improving Bitcoin Privacy and Fungibility

25/5/2020

Abstract

Imagine a future where a user Alice has bitcoins and wants to send them with maximal privacy, so she creates a special kind of transaction. For anyone looking at the blockchain her transaction appears completely normal with her coins seemingly going from address A to address B. But in reality her coins end up in address Z which is entirely unconnected to either A or B.

Now imagine another user, Carol, who isn't too bothered by privacy and sends her bitcoin using a regular wallet which exists today. But because Carol's transaction looks exactly the same as Alice's, anybody analyzing the blockchain must now deal with the possibility that Carol's transaction actually sent her coins to a totally unconnected address. So Carol's privacy is improved even though she didn't change her behaviour, and perhaps had never even heard of this software.

#!/usr/bin/env python
import random, string, time
def rand():
return start_date + random.random() * (end_date - start_date)
def fmt(seconds):
return '[%s]' % time.ctime(seconds)
@dooglus
dooglus / bootstrap.cpp
Created February 21, 2013 06:44
create bootstrap.dat from bitcoin-qt's blk0000?.dat files
// g++ UniversalTimer.o BinaryData.o FileDataPtr.o BtcUtils.o BlockObj.o BlockUtils.o libcryptopp.a -o bootstrap.out -Icryptopp -DUSE_CRYPTOPP -D__STDC_LIMIT_MACROS -lpthread bootstrap.cpp
#include "BlockUtils.h"
int main(void)
{
string btcdir("/home/chris/.bitcoin");
string bootstrap(btcdir + "/" + "bootstrap.dat");
BlockDataManager_FileRefs::GetInstance().SelectNetwork("Main");
BlockDataManager_FileRefs & bdm = BlockDataManager_FileRefs::GetInstance();
def evaluate(hand):
ranks = '23456789TJQKA'
if len(hand) > 5: return max([evaluate(hand[:i] + hand[i+1:]) for i in range(len(hand))])
score, ranks = zip(*sorted((cnt, rank) for rank, cnt in {ranks.find(r): ''.join(hand).count(r) for r, _ in hand}.items())[::-1])
if len(score) == 5: # if there are 5 different ranks it could be a straight or a flush (or both)
if ranks[0:2] == (12, 3): ranks = (3, 2, 1, 0, -1) # adjust if 5 high straight
score = ([1,(3,1,2)],[(3,1,3),(5,)])[len({suit for _, suit in hand}) == 1][ranks[0] - ranks[4] == 4] # high card, straight, flush, straight flush
return score, ranks
Verifying that +dooglus2 is my blockchain ID. https://onename.com/dooglus2
import random, math
num_sims = 1000
num_rolls = 1000
chance = 5/100.0
edge = 1 - 2*chance
start_bank = 1000
risk = 0
while risk < 1:
#!/usr/bin/env python
import hmac
import hashlib
from sys import argv, exit, stderr
def hmac_sha512(key, message):
return hmac.new(key, message, hashlib.sha512).hexdigest()
def roll(server_seed, client_seed, nonce):
# Generate key and message strings.
@dooglus
dooglus / clams.py
Last active January 2, 2016 22:06
clamd in Python, accepting long commands on standard input
#!/usr/bin/python
from __future__ import print_function
import base64, httplib, json, string, sys, re
USER = 'user'; PASS = 'pass'; HOST = '127.0.0.1'; PORT = 30174
class RPC:
def __init__(self, host, port, username, password):
self.authhdr = "Basic %s" % (base64.b64encode("%s:%s" % (username, password)))
self.conn = httplib.HTTPConnection(host, port, False, 30)