pricklybirdlib 1.0.2

Library to convert between binary data and pricklybird strings.
Documentation
  • Coverage
  • 100%
    18 out of 18 items documented9 out of 10 items with examples
  • Size
  • Source code size: 29.76 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.17 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 13s Average build duration of successful builds.
  • all releases: 14s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • ndornseif/rspricklybird
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ndornseif

pricklybirdlib

GitHub License Crate


Overview

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

Documentation is hosted on on docs.rs.

Usage

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])

License

pricklybirdlib is distributed under the terms of the MIT license.