readable_hash/
lib.rs

1//! Generate human-readable strings from SHA-256 hashes.
2
3use sha2::{Digest, Sha256};
4
5/// Syllables used for obfuscating lowercase words.
6pub(crate) const SYLLABLES: [&str; 256] = [
7    "plac", "most ", "sam", "ke", "uth", "arl ", "het", "giv", "fa", "first ", "own ", "li", "van",
8    "form ", "pres", "ond", "men ", "bef", "old ", "agr", "must ", "two ", "ight ", "mak", "cons",
9    "nat", "den", "rem", "inst", "eb", "itt", "iss ", "tak", "ars", "ap", "app", "iz", "wher",
10    "ec", "mad", "cont", "pe", "such ", "lik", "ung", "rec", "gen", "now ", "how ", "urs", "wa",
11    "ver ", "than ", "don", "com", "mo", "ught ", "pa", "min", "vi", "comm", "sho", "thes",
12    "ents ", "then ", "aft", "fe", "ek", "ha", "ins ", "ep", "ich", "acc", "elf", "ans", "can",
13    "ass", "att", "ni", "ex", "work ", "par", "ef", "te", "part ", "ho", "onl", "des", "vo", "tim",
14    "ib", "lo", "has", "tho", "proj", "ert", "gre", "ord", "off ", "stat ", "what ", "ort", "der",
15    "eg", "gut", "ach", "art ", "si", "ett ", "ern ", "als", "enb", "bo", "ud", "ys", "them ",
16    "som", "mor", "act", "unt", "who ", "ac", "ak", "ik", "ish ", "ast ", "when ", "erg", "po",
17    "ne", "ard ", "will ", "go", "ugh ", "ro", "um", "da", "ens", "ow", "ja", "my", "ind", "ok",
18    "op", "wo", "anc", "ill", "abl", "ther", "fo", "she ", "av", "him ", "ot", "oth", "ig", "ov",
19    "its", "ell", "wer", "enc", "ma", "man ", "di", "od", "end ", "do", "up", "re", "no", "im",
20    "le", "ab", "om", "sa", "ul", "ant ", "co", "if", "uld ", "ist ", "hav", "ons ", "la", "we",
21    "from ", "me", "had ", "but ", "her ", "which ", "so", "ag", "int", "se", "est", "ol", "os",
22    "qu", "un", "this ", "ev", "ect ", "ers", "iv", "em", "not ", "am", "by", "ess", "und", "ad",
23    "il", "his", "ir", "all ", "for", "was ", "id", "de", "with ", "et", "that ", "be", "ut", "ic",
24    "us", "el", "ur", "he", "ent ", "as", "or", "al", "ar", "is", "an", "u", "ing ", "at", "it",
25    "es", "to", "and ", "en", "on", "of", "ed ", "o", "in", "er", "i", "a", "y", "the ", "e",
26];
27
28/// Generates a SHA-256 hash and returns it as a syllable string.
29pub fn naive_readable_hash(input: &str) -> String {
30    let mut hasher = Sha256::new();
31    hasher.update(input.as_bytes());
32    let result = hasher.finalize();
33    result
34        .iter()
35        .map(|b| SYLLABLES[*b as usize])
36        .collect::<String>()
37}