| Crates.io | pricklybirdlib |
| lib.rs | pricklybirdlib |
| version | 1.0.2 |
| created_at | 2025-08-31 22:08:39.376811+00 |
| updated_at | 2025-09-01 21:18:27.768742+00 |
| description | Library to convert between binary data and pricklybird strings. |
| homepage | |
| repository | https://github.com/ndornseif/rspricklybird/ |
| max_upload_size | |
| id | 1818922 |
| size | 30,256 |
pricklybird is a method for conversion of
arbitrary binary data into more human-friendly words, where each word represents a single byte.
A CRC-8 checksum is attached to allow the detection of errors during decoding.
0xDEADBEEF becomes turf-port-rust-warn-void, for example.
pricklybirdlib is a rust implementation pricklybird version v1.
Documentation is hosted on on docs.rs.
Basic conversion functions that fully comply with the specification and include the CRC can be used as follows.
use pricklybirdlib::{convert_to_pricklybird, convert_from_pricklybird};
let data = [0x42_u8, 0x43];
let words = convert_to_pricklybird(&data);
// Notice the third word "full" used to encode the CRC.
assert_eq!("flea-flux-full", words);
let recovered_data = convert_from_pricklybird(&words).unwrap();
assert_eq!(vec![0x42, 0x43], recovered_data);
Is is also possible to map word to bytes and bytes to words without the full standard implementation and CRC. The words are encoded as four bytes of ASCII compatible UTF-8, since the wordlist contains no non ASCII characters and all words are four letters long.
use pricklybirdlib::{words_to_bytes, bytes_to_words};
let data = [0x42_u8, 0x43];
let words = bytes_to_words(&data);
// Notice that no CRC is attached, the bytes represent the words: "flea", "flux"
assert_eq!(vec![[102, 108, 101, 97], [102, 108, 117, 120]], words);
let word_str = vec!["flea", "flux"];
let recovered_data = words_to_bytes(&word_str).unwrap();
assert_eq!(vec![0x42, 0x43], recovered_data);
The constants module allows direct access to the WORDLIST used for
mapping bytes to words, and the HASH_TABLE use to map words to bytes.
use pricklybirdlib::constants::{word_hash, HASH_TABLE, WORDLIST};
// Confirm that the word flux maps to the byte 0x43 in both directions.
let word = "flux".as_bytes();
let table_index = word_hash(word[0], word[3]);
let byte_value = HASH_TABLE[table_index];
assert_eq!(0x43, byte_value);
assert_eq!("flux", WORDLIST[0x43])
pricklybirdlib is distributed under the terms of the MIT license.