using System.Text;
public static class Base32
{
private static char[] BASE32_CHARS = {
'a','b','c','d','e','f','g','h'
,'i','j','k','l','m','n','o','p'
,'q','r','s','t','u','v','w','x'
,'y','z','2','3','4','5','6','7'};
private static byte[] rshift = { 3, 6, 1, 4, 7, 2, 5, 0 };
public static string Encode(byte[] data)
{
StringBuilder result = new StringBuilder((data.Length + 4) / 5 << 3);
int loop = 0;
int index = 0;
int val = 0;
bool eod = false;
while (false == eod)
{
int shift = rshift[loop & 7];
if (3 <= shift)
{
val <<= 8;
eod = (data.Length <= index);
if (false == eod)
{
val |= data[index++];
}
}
result.Append(BASE32_CHARS[(val >> shift) & 0x1F]);
loop++;
}
return result.ToString();
}
}
探している人がいるなら、どうぞ。
"="節約版ですので、本物のBase32にするなら、8バイトに足りない分、"="を詰めてください。
Decodeは、今回は使わないから、作ってません(ScalaでDecodeするんですよ)。
使いたい方がいらっしゃるなら、OwnRiskでご自由に。
不具合があるようでしたら、コメントにお願いします。