-
-
Save rust-play/6e2139146ce79f34d1b86a33ce19fe08 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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
| #![allow(deprecated)] | |
| use serde::{Serialize, Deserialize}; | |
| use serde_json; | |
| use sha2::{Sha256, Digest}; | |
| use rand_0_8_5::{thread_rng as rng_legacy, Rng as RngLegacy}; | |
| use rand_0_9_2::{thread_rng as rng_latest, Rng as RngLatest}; | |
| use chrono::Local; | |
| #[derive(Serialize, Deserialize, Debug)] | |
| struct SecurePayload { | |
| id: u64, | |
| content: String, | |
| timestamp: String, | |
| entropy_legacy: u32, | |
| entropy_latest: u32, | |
| } | |
| fn main() { | |
| let mut v8 = rng_legacy(); | |
| let mut v9 = rng_latest(); | |
| let now = Local::now(); | |
| // 1. Generate data using versioned RNGs | |
| let payload = SecurePayload { | |
| id: v9.r#gen(), | |
| content: String::from("System_Override_Protocol"), | |
| timestamp: now.to_rfc3339(), | |
| entropy_legacy: v8.r#gen(), | |
| entropy_latest: v9.r#gen(), | |
| }; | |
| // 2. Serialize to JSON | |
| let json_data = serde_json::to_string_pretty(&payload).expect("Failed to serialize"); | |
| println!("--- Serialized JSON Payload ---\n{}", json_data); | |
| // 3. Generate SHA-256 Hash | |
| let mut hasher = Sha256::new(); | |
| hasher.update(json_data.as_bytes()); | |
| let result = hasher.finalize(); | |
| println!("\n--- Cryptographic Integrity ---"); | |
| println!("SHA-256 Checksum: {:x}", result); | |
| // 4. Comparison logic | |
| if payload.entropy_latest > payload.entropy_legacy { | |
| println!("\nTrend: Entropy increasing across RNG versions."); | |
| } else { | |
| println!("\nTrend: Stable entropy distribution observed."); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment