mirror of https://github.com/dirtbags/fluffy.git
Add bubblebabble
This commit is contained in:
parent
c66c6aea95
commit
26949ae6e9
1
Makefile
1
Makefile
|
@ -17,6 +17,7 @@ TARGETS += entropy
|
||||||
TARGETS += freq
|
TARGETS += freq
|
||||||
TARGETS += histogram
|
TARGETS += histogram
|
||||||
TARGETS += printy
|
TARGETS += printy
|
||||||
|
TARGETS += bubblebabble
|
||||||
|
|
||||||
SCRIPTS += octets
|
SCRIPTS += octets
|
||||||
|
|
||||||
|
|
33
README.md
33
README.md
|
@ -313,10 +313,35 @@ Reads the first number of each line, and prints a histogram.
|
||||||
0a ◙ # 1
|
0a ◙ # 1
|
||||||
41 A ######## 8
|
41 A ######## 8
|
||||||
61 a ################ 16
|
61 a ################ 16
|
||||||
$ echo 'aaaaaaaaAAAAAAAAaaaaaaaa' | freq | histogram -d 4
|
$ echo aaaaaabcccc | freq | histogram
|
||||||
0a ◙ 1
|
0a ◙ # 1
|
||||||
41 A ## 8
|
61 a ###### 6
|
||||||
61 a #### 16
|
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
|
Example Recipes
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in New Issue