public override string Encode(byte[] data)
{
int dataLength = data.Length;
StringBuilder result = new StringBuilder((dataLength + 6) / 7 * 8);
byte x1, x2;
int i;
int length7 = (dataLength / 7) * 7;
for (i = 0; i < length7; i += 7)
{
x1 = data[i];
result.Append(Alphabet[x1 >> 1]);
x2 = data[i + 1];
result.Append(Alphabet[((x1 << 6) & 0x40) | (x2 >> 2)]);
x1 = data[i + 2];
result.Append(Alphabet[((x2 << 5) & 0x60) | (x1 >> 3)]);
x2 = data[i + 3];
result.Append(Alphabet[((x1 << 4) & 0x70) | (x2 >> 4)]);
x1 = data[i + 4];
result.Append(Alphabet[((x2 << 3) & 0x78) | (x1 >> 5)]);
x2 = data[i + 5];
result.Append(Alphabet[((x1 << 2) & 0x7C) | (x2 >> 6)]);
x1 = data[i + 6];
result.Append(Alphabet[((x2 << 1) & 0x7E) | (x1 >> 7)]);
result.Append(Alphabet[x1 & 0x7F]);
}
switch (dataLength - length7)
{
case 1:
x1 = data[i];
result.Append(Alphabet[x1 >> 1]);
result.Append(Alphabet[(x1 << 6) & 0x40]);
result.Append(Special, 6);
break;
case 2:
x1 = data[i];
result.Append(Alphabet[x1 >> 1]);
x2 = data[i + 1];
result.Append(Alphabet[((x1 << 6) & 0x40) | (x2 >> 2)]);
result.Append(Alphabet[((x2 << 5) & 0x60)]);
result.Append(Special, 5);
break;
case 3:
x1 = data[i];
result.Append(Alphabet[x1 >> 1]);
x2 = data[i + 1];
result.Append(Alphabet[((x1 << 6) & 0x40) | (x2 >> 2)]);
x1 = data[i + 2];
result.Append(Alphabet[((x2 << 5) & 0x60) | (x1 >> 3)]);
result.Append(Alphabet[(x1 << 4) & 0x70]);
result.Append(Special, 4);
break;
case 4:
x1 = data[i];
result.Append(Alphabet[x1 >> 1]);
x2 = data[i + 1];
result.Append(Alphabet[((x1 << 6) & 0x40) | (x2 >> 2)]);
x1 = data[i + 2];
result.Append(Alphabet[((x2 << 5) & 0x60) | (x1 >> 3)]);
x2 = data[i + 3];
result.Append(Alphabet[((x1 << 4) & 0x70) | (x2 >> 4)]);
result.Append(Alphabet[(x2 << 3) & 0x78]);
result.Append(Special, 3);
break;
case 5:
x1 = data[i];
result.Append(Alphabet[x1 >> 1]);
x2 = data[i + 1];
result.Append(Alphabet[((x1 << 6) & 0x40) | (x2 >> 2)]);
x1 = data[i + 2];
result.Append(Alphabet[((x2 << 5) & 0x60) | (x1 >> 3)]);
x2 = data[i + 3];
result.Append(Alphabet[((x1 << 4) & 0x70) | (x2 >> 4)]);
x1 = data[i + 4];
result.Append(Alphabet[((x2 << 3) & 0x78) | (x1 >> 5)]);
result.Append(Alphabet[(x1 << 2) & 0x7C]);
result.Append(Special, 2);
break;
case 6:
x1 = data[i];
result.Append(Alphabet[x1 >> 1]);
x2 = data[i + 1];
result.Append(Alphabet[((x1 << 6) & 0x40) | (x2 >> 2)]);
x1 = data[i + 2];
result.Append(Alphabet[((x2 << 5) & 0x60) | (x1 >> 3)]);
x2 = data[i + 3];
result.Append(Alphabet[((x1 << 4) & 0x70) | (x2 >> 4)]);
x1 = data[i + 4];
result.Append(Alphabet[((x2 << 3) & 0x78) | (x1 >> 5)]);
x2 = data[i + 5];
result.Append(Alphabet[((x1 << 2) & 0x7C) | (x2 >> 6)]);
result.Append(Alphabet[(x2 << 1) & 0x7E]);
result.Append(Special);
break;
}
return result.ToString();
}