hide‑something
A lightweight steganography library written in Rust that hides arbitrary textual data inside a carrier text by altering the case of alphabetic characters. The data is first compressed using the DEFLATE algorithm (raw format) to reduce size, then embedded as a bit stream.
📚 Table of Contents
How it works
- Compress the input string with raw DEFLATE (using
flate2). - Prepend a 4‑byte big‑endian length prefix.
- Convert the byte sequence into a bit stream (MSB first).
- Repeat the carrier template until it contains enough alphabetic characters to hold all bits.
- Encode each bit by setting the corresponding alphabetic character to uppercase (bit = 1) or lowercase (bit = 0). Non‑alphabetic characters (digits, punctuation, spaces) remain untouched.
To decode, the process is reversed:
- Extract bits from the case of letters.
- Group bits into bytes (ignoring trailing partial bits).
- Read the length prefix.
- Extract and decompress the payload.
- Convert back to UTF‑8.
The use of DEFLATE compression ensures that even long messages can fit into relatively short carrier texts.
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Or, if you want to use the latest development version from GitHub:
[]
= { = "https://github.com/cherish-ltt/hide-something.git" }
Usage
Basic example
use ;
More examples
- Short message – even a single character can be hidden.
- Long text – compression helps keep the payload small.
- Non‑alphabetic characters – they are preserved exactly as in the template.
API Overview
The library exposes two public functions:
hide_encrypt<T>(info: T, carrier_template: &str) -> Result<String, HideSomethingError>
- Parameters:
info: any type that implementsToString(e.g.,&str,String).carrier_template: a string that will be repeated if needed to provide enough alphabetic characters.
- Returns: a new
Stringwith the hidden data encoded in the case of letters. - Errors:
CarrierTemplateEmpty– if the template contains no alphabetic characters.IoError– if compression fails (wrappedstd::io::Error).
hide_decrypt<T>(info: T) -> Result<String, HideSomethingError>
- Parameters:
info: any type that implementsToString(the hidden text produced byhide_encrypt).
- Returns: the original hidden string.
- Errors:
TooShortData– if the extracted payload is less than 4 bytes.IoError– if decompression fails.Utf8Error– if the decompressed bytes are not valid UTF‑8.
Error Handling
All errors are collected under the HideSomethingError enum:
| Variant | Description |
|---|---|
CarrierTemplateEmpty |
The provided carrier template contains no alphabetic characters (a..z, A..Z). |
TooShortData |
The extracted bit stream could not produce at least 4 bytes for the length prefix. |
IoError |
Underlying I/O or compression/decompression error (from std::io::Error). |
Utf8Error |
Decompressed bytes are not valid UTF‑8 (from std::string::FromUtf8Error). |
The library uses thiserror for ergonomic error handling; you can use ? to propagate errors or match on the enum for custom handling.
Minimum Supported Rust Version (MSRV)
The MSRV is 1.98.0 as specified in Cargo.toml. This version is required for edition 2024 and for some language features used. We may update the MSRV in future minor releases, but we will do so only when necessary and with a clear notice.
License
This project is licensed under the MIT License – see the LICENSE file for details.
Contributing
Contributions are welcome! Feel free to open issues or submit pull requests on GitHub.