Skip to content

Instantly share code, notes, and snippets.

@simon-engledew
Created September 2, 2011 09:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save simon-engledew/1188235 to your computer and use it in GitHub Desktop.
Save simon-engledew/1188235 to your computer and use it in GitHub Desktop.
C-Sharp implemention of the Bubble Babble algorithm
public static class BubbleBabble
{
private static readonly string vowels = "aeiouy";
private static readonly string consonants = "bcdfghklmnprstvzx";
public static string Convert(byte[] bytes)
{
int seed = 1;
int rounds = 1 + bytes.Length / 2;
StringBuilder result = new StringBuilder();
result.Append(consonants[16]);
for (int i = 0; i < rounds; i++)
{
if (i + 1 < rounds || bytes.Length % 2 == 1)
{
result.Append(vowels[(((bytes[2 * i] >> 6) & 3) + seed) % 6]);
result.Append(consonants[(bytes[2 * i] >> 2) & 15]);
result.Append(vowels[((bytes[2 * i] & 3) + seed / 6) % 6]);
if (i + 1 < rounds)
{
result.Append(consonants[(bytes[2 * i + 1] >> 4) & 15]);
result.Append("-");
result.Append(consonants[bytes[2 * i + 1] & 15]);
seed = (seed * 5 + bytes[2 * i] * 7 + bytes[2 * i + 1]) % 36;
}
}
else
{
result.Append(vowels[seed % 6]);
result.Append(consonants[16]);
result.Append(vowels[seed / 6]);
}
}
result.Append(consonants[16]);
return result.ToString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment