-
-
Save rust-play/43da339701f216e1daeff8498c56fead 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::Write; | |
| /// Replicates the 'Highlight' steganography style. | |
| /// Data is hidden in the filter coefficients rather than coordinates. | |
| pub struct HighlightStego { | |
| pub color: String, // #A112ED | |
| } | |
| impl HighlightStego { | |
| pub fn generate_svg(&self, output_path: &str, payload: &[u8]) -> std::io::Result<()> { | |
| let mut svg = format!( | |
| "<svg width='512' height='512' viewBox='0 0 100 100' xmlns='http://www.w3.org/2000/svg'>\n\ | |
| <defs>\n\ | |
| <filter id='stegoFilter'>\n" | |
| ); | |
| // iOS-style encoding: The payload is hidden in the 'values' matrix. | |
| // We use the matrix to 'highlight' the image, but the coefficients are our data. | |
| let mut matrix_values = String::new(); | |
| for &byte in payload.iter().take(20) { | |
| // Normalize byte to a float (0.000 to 0.255) for the matrix | |
| matrix_values.push_str(&format!("{:.3} ", byte as f32 / 1000.0)); | |
| } | |
| // Fill remaining matrix slots if payload is short | |
| while matrix_values.split_whitespace().count() < 20 { | |
| matrix_values.push_str("0 "); | |
| } | |
| svg.push_str(&format!( | |
| " <feColorMatrix type='matrix' values='{}' />\n", | |
| matrix_values.trim() | |
| )); | |
| svg.push_str( | |
| "</filter>\n\ | |
| </defs>\n" | |
| ); | |
| // Drawing the Git Logo with the filter applied | |
| svg.push_str(&format!( | |
| " <rect x='14.6' y='14.6' width='70.8' height='70.8' rx='10' fill='{}' transform='rotate(45 50 50)' filter='url(#stegoFilter)' />\n", | |
| self.color | |
| )); | |
| svg.push_str(" <path d='M45 25 L45 75 M45 50 L70 50' stroke='white' stroke-width='6' stroke-linecap='round' />\n"); | |
| svg.push_str(" <circle cx='45' cy='25' r='8' fill='white' />\n"); | |
| svg.push_str(" <circle cx='45' cy='75' r='8' fill='white' />\n"); | |
| svg.push_str(" <circle cx='70' cy='50' r='8' fill='white' />\n"); | |
| svg.push_str("</svg>"); | |
| let mut file = File::create(output_path)?; | |
| file.write_all(svg.as_bytes())?; | |
| Ok(()) | |
| } | |
| } | |
| fn main() -> std::io::Result<()> { | |
| let stego = HighlightStego { color: "#A112ED".to_string() }; | |
| // Encoding 'BIP-64MOD' into the color matrix | |
| stego.generate_svg("ios_style_carrier.svg", b"BIP-64MOD")?; | |
| println!("iOS Highlight Style Carrier generated."); | |
| println!("Data is embedded in the <feColorMatrix> coefficients."); | |
| Ok(()) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment