Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.