| Crates.io | cat2text |
| lib.rs | cat2text |
| version | 1.0.1 |
| created_at | 2025-01-15 14:53:51.293154+00 |
| updated_at | 2025-01-31 23:41:18.088815+00 |
| description | A port of Cat2Text to Rust, with extra functionality, better documentation, and support for using it as a library as well. |
| homepage | |
| repository | https://github.com/askiiart/cat2text-rs |
| max_upload_size | |
| id | 1517594 |
| size | 29,535 |
This is a port of Cat2Text to Rust, with extra functionality, better documentation, and support for using it as a library as well.
Using the original base4 format, it works like this. First off, each word is equal to a value in base 4:
| Value | Cat sound |
|---|---|
| 0 | meow |
| 1 | mrrp |
| 2 | mreow |
| 3 | mrow |
Then, the text is converted into lowercase, 96 is subtracted from its ASCII value (i.e. "a" (97) -> 1), and it's converted to base 4, which is then replaced by the cat sounds above; Each cat sound is separated by a space (" "), then each word is delimited by a semicolon and a space ("; ").
For example, "i love cats" is translated into:
meow mreow mrrp; meow mrow meow meow mrow mrow mrrp mrrp mreow meow mrrp mrrp; meow meow mrow meow meow mrrp mrrp mrrp meow mrrp meow mrow
Separating out the letters and words:
[ ["meow mreow mrrp"], [ "meow mrow meow", "meow mrow mrow", "mrrp mrrp mreow", "meow mrrp mrrp" ], [ "meow meow mrow", "meow meow mrrp", "mrrp mrrp meow", "mrrp meow mrow" ] ]
To use the library, first off add it as a dependency:
cargo add cat2text
Then just import the relevant functions, and run it like this:
use cat2text::base4::{encode, decode};
let encoded = encode("i love cats".to_string());
assert_eq!(encoded, "meow mreow mrrp; meow mrow meow meow mrow mrow mrrp mrrp mreow meow mrrp mrrp; meow meow mrow meow meow mrrp mrrp mrrp meow mrrp meow mrow");
let decoded = decode(encoded);
assert_eq!(decoded, "i love cats");
Or to encode binary in cat2text's expanded base16 alphabet:
use cat2text::{anybase::bytes::encode, core::bytes::char_length};
let bytes = &[243, 10];
let base = 16;
let char_length = char_length(base);
assert_eq!("mrow~ mrow meow purrrr", encode(bytes, base, char_length));
You can use the library to encode anything up to base 16 - for details, see the docs
To install cat2text, just run the following:
cargo install cat2text
Usage:
A port of Cat2Text to Rust, with extra functionality, better documentation, and support for using it as a library as well.
Usage: cat2text <COMMAND>
Commands:
gen-completion Generate shell completions
encode Encodes text/data to mrow~
decode Decodes mrow~ to text/data
benchmark Benchmark cat2text-rs
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
For example, cat2text encode 'i love cats' to encode i love cats in text mode using the default of base 4.
-b, --base (int): What base to encode/decode using - up to base 16--bytes (flag): Whether to use byte encoding or text encoding-h, --help: Print help-b, --base (integer): What base to encode/decode using - up to base 16--bytes (flag): Whether to use byte encoding or text encoding-i, --iterations (int): How many iterations to run each benchmark for-h, --help: Print helpTo generate shell completions, you can run cat2text gen-completion $(basename $SHELL) | source on *nix systems using bash, zsh, or fish.