This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::collections::HashMap; | |
| use rand::{seq::SliceRandom, thread_rng}; | |
| // --- BQS Constants --- | |
| // Maximum number of Byzantine faults (f or b) the system can tolerate. | |
| const F: u32 = 4; | |
| // The required supermajority count for a client to accept a value as correct. | |
| // A value is only considered valid if F + 1 servers report it, allowing the | |
| // client to mask 'F' colluding malicious responses. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // main.rs - A minimal Crust program with tests | |
| // | |
| #![cfg_attr(not(test), no_std)] | |
| #![cfg_attr(not(test), no_main)] | |
| extern crate libc; | |
| #[cfg(not(test))] | |
| use core::panic::PanicInfo; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // --- Dependencies --- | |
| // This simple example relies only on standard library features. | |
| use std::error::Error; | |
| use std::fmt; | |
| // --- Error Handling --- | |
| /// A simple custom error type for parsing issues. | |
| #[derive(Debug)] | |
| struct ParseError { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // The core concept is that for a number 'n', if 'n % d == 0', then 'n' is divisible by 'd'. | |
| // Divisibility tests rely on properties of the digits. | |
| /// 🔢 Divisibility Tests Module | |
| mod divisibility_tests { | |
| // Helper function to get the sum of digits | |
| pub fn sum_digits(n: u64) -> u64 { | |
| let mut sum = 0; | |
| let mut num = n; | |
| while num > 0 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Verbose Script: Corrected Floating-Point Comparison | |
| fn main() { | |
| // ---------------------------------------------------- | |
| // 1. Define Constants | |
| // ---------------------------------------------------- | |
| const PI: f64 = std::f64::consts::PI; | |
| let gamma_one_half: f64 = PI.sqrt(); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import secrets | |
| from statistics import mean | |
| # secp256k1 parameters | |
| p = 2**256 - 2**32 - 977 | |
| b = 7 # y^2 = x^3 + 7 | |
| def is_quadratic_residue(n): | |
| """Return True if n is a quadratic residue mod p (including 0).""" | |
| if n == 0: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import secrets | |
| # secp256k1 parameters | |
| p = 2**256 - 2**32 - 977 | |
| a = 0 | |
| b = 7 | |
| def random_256bit_int(): | |
| # random 32-byte string interpreted as big-endian integer | |
| return int.from_bytes(secrets.token_bytes(32), "big") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import sys | |
| import secrets | |
| from statistics import mean | |
| p = 2**256 - 2**32 - 977 | |
| b = 7 # y^2 = x^3 + 7 | |
| def is_quadratic_residue(n): | |
| return n == 0 or pow(n, (p - 1) // 2, p) == 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // a 3D Ulam Spiral | |
| // projected onto a 2D grid, | |
| // marking primes with their Z-index. | |
| /// Generates a boolean vector where `is_prime[i]` is true if `i` is a prime number (Sieve of Eratosthenes). | |
| fn sieve_of_eratosthenes(max_value: usize) -> Vec<bool> { | |
| if max_value < 2 { return vec![]; } | |
| let mut is_prime = vec![true; max_value + 1]; | |
| is_prime[0] = false; | |
| is_prime[1] = false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::fmt::{self, Display}; | |
| // Define a type alias for a binary sequence (a vector of 0s and 1s) | |
| type BinarySequence = Vec<u8>; | |
| /// Attempts to demonstrate Cantor's Diagonal Argument. | |
| /// | |
| /// It generates a list of sample binary sequences and constructs a new | |
| /// diagonal sequence that is guaranteed to not be in the list. | |
| fn main() { |
NewerOlder