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() { |
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
| // Filename: archimedes_pi.rs | |
| /// Approximates pi using Archimedes' method by iteratively calculating | |
| /// the semi-perimeter of an inscribed regular polygon with 2^(k+1) sides | |
| /// in a unit circle (r=1). | |
| /// | |
| /// The formula used here is an iterative approach for the semi-perimeter (P_n), | |
| /// where P_n is the semi-perimeter of the n-sided polygon. | |
| /// | |
| /// # Arguments |
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 num_traits::Float; | |
| /// Calculates the lengths of the hypotenuses in the Spiral of Theodorus, | |
| /// which are the square roots of integers starting from sqrt(2). | |
| fn calculate_theodorus_hypotenuses<F: Float>(count: u32) -> Vec<F> { | |
| // We want roots from sqrt(2) up to sqrt(count + 1). | |
| // The number of triangles is 'count'. | |
| let mut lengths = Vec::with_capacity(count as usize); | |
| // The length of the first hypotenuse (the base of the spiral) is sqrt(1^2 + 1^2) = sqrt(2). |
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 sha2::{Digest, Sha256}; | |
| use std::collections::{HashMap, HashSet}; | |
| use std::fs; | |
| use std::io::{self, Read}; | |
| use serde::{Serialize, Deserialize}; | |
| use chrono::Utc; | |
| // APPROVED DEPENDENCY: Using data_encoding for all hex operations | |
| use data_encoding::HEXUPPER; | |
| // ==================================================================== |
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 sha2::{Digest, Sha256}; | |
| use std::collections::{HashMap, HashSet}; | |
| use std::fs; | |
| use std::io::{self, Read}; | |
| use serde::{Serialize, Deserialize}; | |
| use chrono::Utc; | |
| // APPROVED DEPENDENCY: Using data_encoding for all hex operations | |
| use data_encoding::HEXUPPER; | |
| // ==================================================================== |
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::net::{TcpListener, TcpStream, /*ToSocketAddrs, */SocketAddr}; | |
| use std::time::Duration; | |
| use std::thread; | |
| use std::io::{self, Read, Write}; | |
| // --- Configuration --- | |
| const TARGET_IP: &str = "127.0.0.1"; // The IP the scanner checks | |
| const TIMEOUT_MS: u64 = 500; // Connection timeout in milliseconds | |
| // --------------------- |