# stegtext
Text [steganography][] command-line tool and library.
Links:
- [stegtext Git Repository (codeberg.org)][codeberg-stegtext]
- [stegtext Package Page (crates.io)][crates-io-stegtext]
- [stegtext API Documentation (docs.rs)][docs-rs-stegtext]
## 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][tech-details] 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][crates-io-stegtext] with `cargo
install`:
```
cargo install stegtext
```
Install directly from the `main` branch of the [Git
repository][codeberg-stegtext]:
```
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:
```rust
// secret
const SECRET: [u8; 5] = *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!(stegtext::encode(&SECRET, TEXT)?, EXP);
```
Get secret from text:
```rust
// 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!(stegtext::decode(TEXT)?, "hello");
```
Get text embedding capacity:
```rust
// 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!(stegtext::capacity(TEXT), 23);
```
Additional documentation is available here: [stegtext API
documentation][docs-rs-stegtext].
[steganography]: https://en.wikipedia.org/wiki/Steganography
"Steganography (Wikipedia)"
[utf-8]: https://en.wikipedia.org/wiki/UTF-8
"UTF-8 (Wikipedia)"
[homoglyph]: https://en.wikipedia.org/wiki/Homoglyph
"Homoglyph (Wikipedia)"
[homoglyphs]: https://en.wikipedia.org/wiki/Homoglyph
"Homoglyph (Wikipedia)"
[idn homograph attack]: https://en.wikipedia.org/wiki/IDN_homograph_attack#Cyrillic
"IDN homograph attack (Wikipedia)"
[stegtext]: https://codeberg.org/pablotron/stegtext
"stegtext"
[codeberg-stegtext]: https://codeberg.org/pablotron/stegtext
"stegtext Git Repository (codeberg.org)"
[crates-io-stegtext]: https://crates.io/crates/stegtext
"stegtext Package Page (crates.io)"
[docs-rs-stegtext]: https://docs.rs/stegtext
"stegtext API Documentation (docs.rs)"
[rust]: https://rust-lang.org/
"Rust programming language"
[unicode]: https://en.wikipedia.org/wiki/Unicode
"Unicode (Wikipedia)"
[podman]: https://podman.io/
"Podman: open source container management engine"
[tech-details]: https://docs.rs/stegtext/latest/stegtext/#technical-details
"Technical Details section of the stegtext API Documentation (docs.rs)"
[container]: https://en.wikipedia.org/wiki/Containerization_(computing)
"Containerization (Wikipedia)"