pub fn ghost_encode(
image_bytes: &[u8],
message: &str,
passphrase: &str,
) -> Result<Vec<u8>, StegoError>Expand description
Encode a text message into a cover JPEG using Ghost mode.
§Arguments
image_bytes: Raw bytes of the cover JPEG image.message: The plaintext message to embed (must fit within capacity).passphrase: Used for both structural key derivation and encryption.
§Returns
The stego JPEG image as bytes, or an error if the image is too small or the message exceeds the embedding capacity.
§Errors
StegoError::InvalidJpegifimage_bytesis not a valid baseline JPEG.StegoError::NoLuminanceChannelif the image has no Y component.StegoError::ImageTooSmallif the cover has too few usable coefficients.StegoError::MessageTooLargeif the message exceeds STC capacity.
Examples found in repository?
examples/test_encode.rs (line 32)
8fn main() {
9 let args: Vec<String> = std::env::args().collect();
10 if args.len() < 4 {
11 eprintln!("Usage: test_encode <input.jpg> <message> <passphrase>");
12 eprintln!(" test_encode --decode <stego.jpg> <passphrase>");
13 std::process::exit(1);
14 }
15
16 if args[1] == "--decode" {
17 let stego = fs::read(&args[2]).expect("Could not read stego image");
18 match phasm_core::ghost_decode(&stego, &args[3]) {
19 Ok(payload) => {
20 println!("Decoded message: {}", payload.text);
21 for f in &payload.files {
22 println!(" File: {} ({} bytes)", f.filename, f.content.len());
23 }
24 }
25 Err(e) => eprintln!("Decode failed: {:?}", e),
26 }
27 } else {
28 let cover = fs::read(&args[1]).expect("Could not read cover image");
29 let message = &args[2];
30 let passphrase = &args[3];
31
32 let stego = phasm_core::ghost_encode(&cover, message, passphrase)
33 .expect("Encode failed");
34
35 let out_path = args[1].replace(".jpg", "_stego.jpg").replace(".JPG", "_stego.jpg");
36 fs::write(&out_path, &stego).expect("Could not write output");
37 println!("Stego image written to: {}", out_path);
38 println!("Original: {} bytes, Stego: {} bytes", cover.len(), stego.len());
39 }
40}