fluffy

Network Archaeology tools for Unix
git clone https://git.woozle.org/neale/fluffy.git

Neale Pickett  ·  2024-03-28

bubblebabble.c

 1#include <stdio.h>
 2
 3/** Compute bubble babble for input buffer.
 4 *
 5 * The generated output will be of length 6*((inlen/2)+1), including the
 6 * trailing NULL.
 7 *
 8 * Test vectors:
 9 *     `' (empty string) `xexax'
10 *     `1234567890'      `xesef-disof-gytuf-katof-movif-baxux'
11 *     `Pineapple'       `xigak-nyryk-humil-bosek-sonax'
12 */
13static char const consonants[] = "bcdfghklmnprstvz";
14static char const vowels[]     = "aeiouy";
15
16int
17main(int argc, char *argv[])
18{
19  int seed = 1;
20
21  putchar('x');
22  while (1) {
23    int c;
24
25    c = getchar();
26    if (EOF == c) {
27      putchar(vowels[seed % 6]);
28      putchar('x');
29      putchar(vowels[seed / 6]);
30      break;
31    }
32
33    putchar(vowels[(((c >> 6) & 3) + seed) % 6]);
34    putchar(consonants[(c >> 2) & 15]);
35    putchar(vowels[((c & 3) + (seed / 6)) % 6]);
36
37    seed = (seed * 5) + (c * 7);
38    c = getchar();
39    seed = (seed + c) % 36;
40
41    if (EOF == c) {
42      break;
43    }
44    putchar(consonants[(c >> 4) & 15]);
45    putchar('-');
46    putchar(consonants[c & 15]);
47  }
48
49  putchar('x');
50  putchar('\n');
51
52  return 0;
53}