-
-
Save rust-play/74306a81f56f0bff8cdd457450a1fa85 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
| use std::fs::File; | |
| use std::io::{Read, Write}; | |
| use std::path::Path; | |
| /// A sovereign SVG steganography tool using zero external dependencies. | |
| pub struct SvgStego { | |
| pub width: u32, | |
| pub height: u32, | |
| } | |
| impl SvgStego { | |
| pub fn new(width: u32, height: u32) -> Self { | |
| Self { width, height } | |
| } | |
| /// Encodes a byte slice into a hidden 'phantom' path within an SVG. | |
| /// Each byte is stored in the decimal place of a coordinate. | |
| pub fn encode<P: AsRef<Path>>(&self, path: P, payload: &[u8]) -> std::io::Result<()> { | |
| let mut svg = format!( | |
| "<svg width='{}' height='{}' xmlns='http://www.w3.org/2000/svg'>\n", | |
| self.width, self.height | |
| ); | |
| // Background layer | |
| svg.push_str(" <rect width='100%' height='100%' fill='#1a1a1a' />\n"); | |
| svg.push_str(" <text x='20' y='40' fill='white' font-family='monospace'>BIP-64MOD Context Carrier</text>\n"); | |
| // The "Phantom Path" | |
| // We use a polyline where the Y-coordinates hold our data bytes. | |
| // Format: y='[BASE_POS].[BYTE_VALUE]' | |
| svg.push_str(" <!-- BEGIN PHANTOM DATA -->\n"); | |
| svg.push_str(" <polyline points='"); | |
| for (i, &byte) in payload.iter().enumerate() { | |
| let x = i * 5; | |
| // Store the byte (0-255) as a 3-digit decimal tail | |
| svg.push_str(&format!("{}.{:03},{} ", x, byte, i * 2)); | |
| } | |
| svg.push_str("' fill='none' stroke='none' pointer-events='none' />\n"); | |
| svg.push_str(" <!-- END PHANTOM DATA -->\n"); | |
| svg.push_str("</svg>"); | |
| let mut file = File::create(path)?; | |
| file.write_all(svg.as_bytes())?; | |
| Ok(()) | |
| } | |
| /// Extracts the hidden payload by parsing the polyline coordinates. | |
| pub fn decode<P: AsRef<Path>>(&self, path: P) -> std::io::Result<Vec<u8>> { | |
| let mut file = File::open(path)?; | |
| let mut content = String::new(); | |
| file.read_to_string(&mut content)?; | |
| let mut payload = Vec::new(); | |
| // Simple manual parsing to find the phantom polyline | |
| if let Some(start_idx) = content.find("points='") { | |
| let points_section = &content[start_idx + 8..]; | |
| if let Some(end_idx) = points_section.find("'") { | |
| let points_str = &points_section[..end_idx]; | |
| for point in points_str.split_whitespace() { | |
| if let Some(comma_idx) = point.find(',') { | |
| let x_coord = &point[..comma_idx]; | |
| if let Some(dot_idx) = x_coord.find('.') { | |
| let byte_str = &x_coord[dot_idx + 1..]; | |
| if let Ok(byte_val) = byte_str.parse::<u8>() { | |
| payload.push(byte_val); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| Ok(payload) | |
| } | |
| } | |
| fn main() -> std::io::Result<()> { | |
| let carrier = SvgStego::new(800, 600); | |
| // Example: Encoding the BIP-64MOD context + GCC state | |
| let secret_payload = b"BIP-64MOD_REDUCE_DATA_2026_GCC_ACTIVE"; | |
| println!("--- Sovereign SVG Stego Test ---"); | |
| println!("Encoding payload: {:?}", String::from_utf8_lossy(secret_payload)); | |
| // 1. Create the carrier | |
| carrier.encode("carrier.svg", secret_payload)?; | |
| println!("Carrier generated: carrier.svg"); | |
| // 2. Decode the carrier to verify integrity | |
| let recovered = carrier.decode("carrier.svg")?; | |
| println!("Recovered payload: {:?}", String::from_utf8_lossy(&recovered)); | |
| if secret_payload == &recovered[..] { | |
| println!("SUCCESS: State preserved through vector transformation."); | |
| } else { | |
| println!("FAILURE: Bit-drift detected."); | |
| } | |
| Ok(()) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment