From 26949ae6e97399b2bd4e56c8713bb40d1a7fa8f3 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Thu, 28 Mar 2024 15:59:36 -0600 Subject: [PATCH] Add bubblebabble --- Makefile | 1 + README.md | 33 +++++++++++++++++++++++++++---- bubblebabble.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+), 4 deletions(-) create mode 100755 bubblebabble.c diff --git a/Makefile b/Makefile index 62cd707..5944e90 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ TARGETS += entropy TARGETS += freq TARGETS += histogram TARGETS += printy +TARGETS += bubblebabble SCRIPTS += octets diff --git a/README.md b/README.md index 1ed3eb5..a766396 100644 --- a/README.md +++ b/README.md @@ -313,10 +313,35 @@ Reads the first number of each line, and prints a histogram. 0a ◙ # 1 41 A ######## 8 61 a ################ 16 - $ echo 'aaaaaaaaAAAAAAAAaaaaaaaa' | freq | histogram -d 4 - 0a ◙ 1 - 41 A ## 8 - 61 a #### 16 + $ echo aaaaaabcccc | freq | histogram + 0a ◙ # 1 + 61 a ###### 6 + 62 b # 1 + 63 c #### 4 + $ echo aaaaaabcccc | freq | histogram | sort -nk 4 + 0a ◙ # 1 + 62 b # 1 + 63 c #### 4 + 61 a ###### 6 + + +## bubblebabble: print bubblebabble digest of input + +Prints a [bubblebabble digest](https://web.mit.edu/kenta/www/one/bubblebabble/spec/jrtrjwzi/draft-huima-01.txt) +of the input. + +This is a *digest*, not a *hash*: +it can be reversed. +If you write `unbubblebabble` before I do, +please send it to me :) + + $ printf '' | bubblebabble + xexax + $ printf 1234567890 | bubblebabble + xesef-disof-gytuf-katof-movif-baxux + $ printf Pineapple | bubblebabble + xigak-nyryk-humil-bosek-sonax + Example Recipes diff --git a/bubblebabble.c b/bubblebabble.c new file mode 100755 index 0000000..4bd5f40 --- /dev/null +++ b/bubblebabble.c @@ -0,0 +1,53 @@ +#include + +/** Compute bubble babble for input buffer. + * + * The generated output will be of length 6*((inlen/2)+1), including the + * trailing NULL. + * + * Test vectors: + * `' (empty string) `xexax' + * `1234567890' `xesef-disof-gytuf-katof-movif-baxux' + * `Pineapple' `xigak-nyryk-humil-bosek-sonax' + */ +static char const consonants[] = "bcdfghklmnprstvz"; +static char const vowels[] = "aeiouy"; + +int +main(int argc, char *argv[]) +{ + int seed = 1; + + putchar('x'); + while (1) { + int c; + + c = getchar(); + if (EOF == c) { + putchar(vowels[seed % 6]); + putchar('x'); + putchar(vowels[seed / 6]); + break; + } + + putchar(vowels[(((c >> 6) & 3) + seed) % 6]); + putchar(consonants[(c >> 2) & 15]); + putchar(vowels[((c & 3) + (seed / 6)) % 6]); + + seed = (seed * 5) + (c * 7); + c = getchar(); + seed = (seed + c) % 36; + + if (EOF == c) { + break; + } + putchar(consonants[(c >> 4) & 15]); + putchar('-'); + putchar(consonants[c & 15]); + } + + putchar('x'); + putchar('\n'); + + return 0; +}