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 | |
| // --------------------- |
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::env; | |
| fn env_vars() { | |
| // Iterate over all environment variables. | |
| for (key, value) in env::vars() { | |
| println!("{}: {}", key, value); | |
| } | |
| // You can also filter the environment variables. | |
| println!("\nFiltered environment variables:"); |
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
| // Only using standard library features for this illustrative concept, | |
| // as the listed crates don't provide a direct, safe XOR-list implementation. | |
| use std::ptr; | |
| use std::mem; | |
| // --- A simplified structure for an XOR-linked list node --- | |
| struct Node { | |
| pub value: u32, | |
| // The "link" is the XOR of the *pointers* to the previous and next nodes. |
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
| // 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 | |
| } |
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::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. |
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
| // 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). |