Skip to content

Instantly share code, notes, and snippets.

View RandyMcMillan's full-sized avatar
🛰️
Those who know - do not speak of it.

@RandyMcMillan RandyMcMillan

🛰️
Those who know - do not speak of it.
View GitHub Profile
@RandyMcMillan
RandyMcMillan / hash_to_string_hamming_distance.rs
Last active January 25, 2025 16:45 — forked from rust-play/playground.rs
hash_to_string_hamming_distance.rs
use sha2::{Digest, Sha256};
/// Calculates the Hamming distance between two SHA-256 hashes.
///
/// This function takes two byte slices representing SHA-256 hashes and returns
/// the number of bits that differ between them.
fn hamming_distance_sha256(hash1: &[u8], hash2: &[u8]) -> u32 {
assert_eq!(hash1.len(), 32, "Invalid hash1 length");
assert_eq!(hash2.len(), 32, "Invalid hash2 length");
@RandyMcMillan
RandyMcMillan / hamming_distance.rs
Last active January 25, 2025 16:05 — forked from rust-play/playground.rs
hamming_distance.rs
use sha2::{Digest, Sha256};
/// Calculates the Hamming distance between two SHA-256 hashes.
///
/// This function takes two byte slices representing SHA-256 hashes and returns
/// the number of bits that differ between them.
fn hamming_distance_sha256(hash1: &[u8], hash2: &[u8]) -> u32 {
assert_eq!(hash1.len(), 32, "Invalid hash1 length");
assert_eq!(hash2.len(), 32, "Invalid hash2 length");
@RandyMcMillan
RandyMcMillan / get_blocktemplate.rs
Created January 25, 2025 03:30 — forked from portlandhodl/main.rs
Get Block Template Rust Example 1
use actix_web::{get, web, App, HttpResponse, HttpServer, Responder};
use bitcoincore_rpc::{Auth, Client, RpcApi};
use serde_json::Value;
struct AppState {
btc_client: Client,
}
#[get("/blocktemplate")]
async fn get_block_template(data: web::Data<AppState>) -> impl Responder {
@RandyMcMillan
RandyMcMillan / hamming_distance.rs
Last active January 19, 2025 21:39 — forked from rust-play/playground.rs
hamming_distance.rs
use sha2::{Digest, Sha256};
/// Calculates the Hamming distance between two SHA-256 hashes.
///
/// This function takes two byte slices representing SHA-256 hashes and returns
/// the number of bits that differ between them.
fn hamming_distance_sha256(hash1: &[u8], hash2: &[u8]) -> u32 {
assert_eq!(hash1.len(), 32, "Invalid hash1 length");
assert_eq!(hash2.len(), 32, "Invalid hash2 length");
@RandyMcMillan
RandyMcMillan / hamming_distance.rs
Last active January 19, 2025 21:22 — forked from rust-play/playground.rs
hamming_distance.rs
use sha2::{Digest, Sha256};
/// Calculates the Hamming distance between two SHA-256 hashes.
///
/// This function takes two byte slices representing SHA-256 hashes and returns
/// the number of bits that differ between them.
fn hamming_distance_sha256(hash1: &[u8], hash2: &[u8]) -> u32 {
assert_eq!(hash1.len(), 32, "Invalid hash1 length");
assert_eq!(hash2.len(), 32, "Invalid hash2 length");
@RandyMcMillan
RandyMcMillan / hamming_distance.rs
Last active January 19, 2025 21:15 — forked from rust-play/playground.rs
hamming_distance.rs
use sha2::{Digest, Sha256};
/// Calculates the Hamming distance between two SHA-256 hashes.
///
/// This function takes two byte slices representing SHA-256 hashes and returns
/// the number of bits that differ between them.
fn hamming_distance_sha256(hash1: &[u8], hash2: &[u8]) -> u32 {
assert_eq!(hash1.len(), 32, "Invalid hash1 length");
assert_eq!(hash2.len(), 32, "Invalid hash2 length");

Reusable taproot addresses

Abstract

This document proposes a new scheme to avoid address reuse while retaining some of the convenience of address reuse, keeping recoverability purely from Bitcoin time chain and avoiding visible fingerprint. The scheme has negligible average overhead.

Motivation

@RandyMcMillan
RandyMcMillan / threads_channel.rs
Last active January 18, 2025 15:17 — forked from rust-play/playground.rs
threads_channel.rs
use std::sync::mpsc::{Sender, Receiver};
use std::sync::mpsc;
use std::thread;
static NTHREADS: i32 = 3;
fn main() {
// Channels have two endpoints: the `Sender<T>` and the `Receiver<T>`,
// where `T` is the type of the message to be transferred
// (type annotation is superfluous)
@RandyMcMillan
RandyMcMillan / threads.rs
Last active January 18, 2025 15:13 — forked from rust-play/playground.rs
threads.rs
use std::thread;
const NTHREADS: u32 = 10;
// This is the `main` thread
fn main() {
// Make a vector to hold the children which are spawned.
let mut children = vec![];
for i in 0..NTHREADS {
@RandyMcMillan
RandyMcMillan / tcp_stream.rs
Created January 14, 2025 00:12 — forked from rust-play/playground.rs
Code shared from the Rust Playground
use std::fmt;
use std::net::{TcpStream, SocketAddr, ToSocketAddrs};
use std::io::prelude::*;
use std::collections::*;
#[derive(Debug)]
pub enum Method {
GET,
POST,
PUT,