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 / create_getter.rs
Last active October 25, 2025 12:49 — forked from rust-play/playground.rs
create_getter.rs
// 1. Declarative Macro Definition
// This macro takes a field identifier ($field:ident) and generates a public
// getter method with the same name.
macro_rules! create_getter {
($field:ident) => {
// The generated code:
pub fn $field(&self) -> &str {
// Assumes the field is a String, and returns a string slice (&str)
&self.$field
}
@RandyMcMillan
RandyMcMillan / faux_polar_ecc.rs
Last active October 24, 2025 12:37 — forked from rust-play/playground.rs
faux_polar_ecc.rs
use std::f64::consts::PI;
// Note: This implementation uses f64 (floating-point) for the polar coordinates (r, theta)
// and trigonometric functions (sin, cos). This approach is for **geometric demonstration** // and is NOT how Elliptic Curve Cryptography (ECC) is performed, as ECC requires
// all arithmetic to be done with **integers** in a finite field (modulo P).
// The equation evaluated is:
// r^2 * sin^2(θ) = (A_std * r^3 * cos^3(θ) + B_std * r * cos(θ) + C_std) mod P
/// Evaluates the polar form of the Elliptic Curve equation.
@RandyMcMillan
RandyMcMillan / faux_ecc.rs
Last active October 24, 2025 12:28 — forked from rust-play/playground.rs
faux_ecc.rs
// Note: In real ECC, the modulus P is a large prime (256 bits or more),
// which requires an external crate like `num-bigint` or `crypto-bigint`.
// This example uses u128, which is only 128 bits, for demonstration purposes.
// We will map the general equation to the standard Weierstrass form over a finite field:
// LHS: R * sin^2(θ) -> y_squared
// RHS: A*(r/cos(θ))^3 + B*(r/cos(θ))^1 + C -> A_std * x^3 + B_std * x + C_std
/// Evaluates the right-hand side of the Elliptic Curve equation (Weierstrass form)
/// over a finite field, using only Rust's standard library integer types (u128).
@RandyMcMillan
RandyMcMillan / shot-htlc.md
Created October 22, 2025 11:33 — forked from moonsettler/shot-htlc.md
SHOT - Schnorr HTLC Obfuscation Technique

SHOT - Schnorr HTLC Obfuscation Technique

Taproot internal key aggregation

  • P = p·G taproot internal public key
  • p = a·b taproot internal private key

Alice and Bob reveal each other their pubkey for the session, and then both can generate the same address.

  • A = a·G Alice (buyer of UTXO)
@RandyMcMillan
RandyMcMillan / faux_bdhke.rs
Last active October 22, 2025 04:08 — forked from rust-play/playground.rs
faux_bdhke.rs
//// src/main.rs
use std::collections::HashMap;
// --- PLACEHOLDER TYPES (Replacing ECC Types) ---
// In a real implementation, these would be Elliptic Curve Points or Scalars.
type MintPrivateKey = u64; // k
type MintPublicKey = u64; // K = k * G
type UserSecret = u64; // x
type RandomPoint = u64; // Y = hash_to_curve(x)
@RandyMcMillan
RandyMcMillan / simple_ec.rs
Created October 18, 2025 16:24 — forked from rust-play/playground.rs
simple_ec.rs
//// The prime modulus for the finite field GF(17)
const P: i64 = 17;
// Curve parameters: y^2 = x^3 + A*x + B (mod P)
const A: i64 = 2;
const B: i64 = 3;
/// Represents a point on the elliptic curve.
/// The point is (x, y). The identity point (Point at Infinity) is represented
/// by (0, 0) since the point (0, 0) is not on this curve (0^2 != 0^3 + 2*0 + 3 mod 17).
@RandyMcMillan
RandyMcMillan / viete_pi_hex.rs
Last active October 18, 2025 13:17 — forked from rust-play/playground.rs
viete_pi_hex.rs
use std::f64::consts::PI;
/// Calculates an approximation of Pi using Viète's formula.
///
/// The formula is based on an infinite product of terms involving nested square roots.
/// This function approximates the product up to a given number of iterations.
///
/// # Arguments
///
/// * `iterations` - The number of terms to include in the product. More iterations
@RandyMcMillan
RandyMcMillan / golden_ratio.rs
Last active October 15, 2025 12:00 — forked from rust-play/playground.rs
golden_ratio.rs
fn main() {
// The Golden Ratio is (1 + sqrt(5)) / 2
let five = 5.0f64;
// --- Floating-Point Types (Accurate Representation) ---
// f64: Double-precision floating point (default and most precise)
let phi_f64: f64 = (1.0 + five.sqrt()) / 2.0;
// f32: Single-precision floating point (less precision)
let phi_f32: f32 = (1.0f32 + (5.0f32).sqrt()) / 2.0f32;
@RandyMcMillan
RandyMcMillan / faux_hmac_with_test.rs
Last active October 14, 2025 12:56 — forked from rust-play/playground.rs
faux_hmac_with_test.rs
//#![no_std]
extern crate alloc;
use alloc::vec::Vec;
/// Placeholder for the real SHA-256 function.
/// It only uses the length of the data to generate a predictable output.
fn sha256_placeholder(data: &[u8]) -> [u8; 32] {
let mut hash = [0u8; 32];
let len_bytes = (data.len() as u32).to_le_bytes();
hash[0..4].copy_from_slice(&len_bytes);
@RandyMcMillan
RandyMcMillan / faux_hmac.rs
Last active October 14, 2025 12:45 — forked from rust-play/playground.rs
faux_hmac.rs
//#![no_std]
fn sha256_placeholder(data: &[u8]) -> [u8; 32] {
let mut hash = [0u8; 32];
let len_bytes = (data.len() as u32).to_le_bytes();
hash[0..4].copy_from_slice(&len_bytes);
hash
}
const SHA256_BLOCK_SIZE: usize = 64;