stegtext
Text steganography command-line tool and library.
Links:
- stegtext Git Repository (codeberg.org)
- stegtext Package Page (crates.io)
- stegtext API Documentation (docs.rs)
How It Works
Unicode has many homoglyphs; that is, different characters with the same appearance.
This tool hides a secret value in plain text by selectively replacing characters with homoglyphs.
The encoded result is visually indistinguishable from the plain text.
You can encode up to 4095 bytes of secret data, depending on the embedding capacity (the number of characters with homoglyphs) of the plain text.
See the Technical Details section of the API documentation for additional details.
Example
Hide a secret message in plain text:
# show "input.txt"
$ cat input.txt
The Hitchhiker's Guide to the Galaxy is a 1979 science fiction comedy
novel by English author Douglas Adams, adapted from the first four parts
of his radio comedy series of the same name.
# hide secret, write to "hidden.txt"
$ stegtext encode 'hi there' < input.txt > hidden.txt
# show "hidden.txt"
$ cat hidden.txt
Тhe Нitchhiker'ѕ Guide to the Galaxy is a 1979 ѕcіеncе fictіon соmedy
novel by Englіsh author Douglаs Аdаmѕ, adapted frоm the fіrѕt four рartѕ
of hiѕ rаdio сomedу ѕеriеs оf the sаmе name.
# read secret from "hidden.txt"
$ stegtext decode < hidden.txt
hi there
Install
Install the stegtext package with cargo install:
cargo install stegtext
Install directly from the main branch of the Git
repository:
cargo install --git https://codeberg.org/pablotron/stegtext
Install as a container with Podman:
# pull container image
podman pull codeberg.org/pablotron/stegtext:latest
Run the stegtext container:
# run ephemeral stegtext container, read text from "input.txt", hide
# secret "hi there", and write result to "hidden.txt"
podman run --rm -i codeberg.org/pablotron/stegtext encode 'hi there' < input.txt > hidden.txt
Build
Build release binary using cargo build:
# clone git repo
git clone https://codeberg.org/pablotron/stegtext
cd stegtext
# build release binary
cargo build --release
Build stegtext container image using Podman:
# clone git repo
git clone https://codeberg.org/pablotron/stegtext
cd stegtext
# build image
podman build -t stegtext:latest .
Run previously-built stegtext container:
# run ephemeral stegtext container, read text from "input.txt", hide
# secret "hi there", and write result to "hidden.txt"
podman run --rm -i stegtext:latest encode 'hi there' < input.txt > hidden.txt
Usage
Available subcommands:
capacity: Print embedding capacity of input, in bytes.encode: Embed secret in text and then print result.decode: Extract secret from text and print it.help: Print usage.
Rust Library
stegtext can also be used as a Rust library. Here are a couple of examples.
Hide secret in text:
// secret
const SECRET: = *b"hello";
// input text
const TEXT: &str = "\
Тhe Нitсhhikеr's Guіdе to thе Galaxy is a 1979 ѕcіеncе fiсtion соmedy
novеl bу Englіѕh author Douglаѕ Adаmѕ, adарtеd frоm the fіrѕt four parts
of hiѕ radiо соmedу ѕеriеѕ оf thе sаmе name.";
// expected output
const EXP: &str = "\
Тhe Нitсhhikеr's Guide to the Galaxy is a 1979 ѕcіеncе fiсtion соmedy
novеl bу Englіѕh author Douglаѕ Adаmѕ, adарtеd frоm the fіrѕt four parts
of hiѕ radiо соmedу ѕеriеѕ оf thе sаmе name.";
// encode secret, check result
assert_eq!;
Get secret from text:
// text with embedded secret
const TEXT: &str = "\
Тhe Нitсhhikеr's Guide to the Galaxy is a 1979 ѕcіеncе fiсtion соmedy
novеl bу Englіѕh author Douglаѕ Adаmѕ, adарtеd frоm the fіrѕt four parts
of hiѕ radiо соmedу ѕеriеѕ оf thе sаmе name.";
// decode secret, check result
assert_eq!;
Get text embedding capacity:
// input text
const TEXT: &str = "\
Тhe Нitсhhikеr's Guіdе to thе Galaxy is a 1979 ѕcіеncе fiсtion соmedy
novеl bу Englіѕh author Douglаѕ Adаmѕ, adарtеd frоm the fіrѕt four parts
of hiѕ radiо соmedу ѕеriеѕ оf thе sаmе name. Іt centrеѕ оn the
misаdvеntureѕ оf Arthur Dent, the оnly man tо ѕurvive the destruction of
Earth, as he roams the cosmos and learns the truth behind his very
existence. The novel's namesake is an in-universe electronic travel
guide written in the form of an encyclopaedia, through which the story
is framed.";
// calculate capacity, check result
assert_eq!;
Additional documentation is available here: stegtext API documentation.