This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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