Skip to content

Commit

Permalink
Add bubblebabble
Browse files Browse the repository at this point in the history
  • Loading branch information
nealey authored and neale-pnnl committed Mar 28, 2024
1 parent c66c6ae commit 26949ae
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 4 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ TARGETS += entropy
TARGETS += freq
TARGETS += histogram
TARGETS += printy
TARGETS += bubblebabble

SCRIPTS += octets

Expand Down
33 changes: 29 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
53 changes: 53 additions & 0 deletions bubblebabble.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <stdio.h>

/** 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;
}

0 comments on commit 26949ae

Please sign in to comment.