| Crates.io | syndrome-trellis-codes |
| lib.rs | syndrome-trellis-codes |
| version | 0.1.1 |
| created_at | 2026-01-12 14:49:35.085331+00 |
| updated_at | 2026-01-18 17:33:23.950643+00 |
| description | Rust implementation of Syndrome-Trellis Codes |
| homepage | |
| repository | https://gitlab.com/harrose/syndrome-trellis-codes |
| max_upload_size | |
| id | 2037902 |
| size | 20,714 |
Implementation of Syndrome-Trellis Codes, a widely used embedding method in adaptive steganography.
Proposed in Minimizing Additive Distortion in Steganography using Syndrome-Trellis Codes.
It's recommended to compile with the following CPU instructions enabled:
RUSTFLAGS="-C target-feature=+avx2,+fma,+bmi1"
Enabling these instructions has shown a significant performance increase.
use syndrome_trellis_codes::{HHat, embed, extract};
// `x` is usually an array of the least significant bits of image pixels
let x = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1];
// Cost map `rho`: how "expensive" it is to modify each bit
// High costs (like 10.0) mark "wet" bits that shouldn't be touched
// They are usually called "wet pixels" because image steganography is the most common
let rho = [
0.2, 10.0, 10.0, 0.5, 10.0, 10.0, 0.2, 0.2, 0.2, 5.0, 0.2, 5.0, 5.0, 0.2, 5.0,
];
// Our secret message
let m = [1, 1, 0];
let h_hat = HHat::from_dims(7, 5).unwrap();
let (y, distortion) = embed(&x, &rho, &m, h_hat).unwrap();
// y = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1]
// ^ this bit was changed
// distortion = 0.2
let m_extracted = extract(&y, h_hat);
assert_eq!(m.to_vec(), m_extracted);