public static string EncodeGuid(Guid guid)
{
uint[] num = new uint[6];
char[] str = new char[22];
int i, n;
byte[] b = guid.ToByteArray();
// Creation of six 32 Bit integers from the components of the GUID structure
num[0] = (uint)(BitConverter.ToUInt32(b, 0) / 16777216);
num[1] = (uint)(BitConverter.ToUInt32(b, 0) % 16777216);
num[2] = (uint)(BitConverter.ToUInt16(b, 4) * 256 + BitConverter.ToInt16(b, 6) / 256);
num[3] = (uint)((BitConverter.ToUInt16(b, 6) % 256) * 65536 + b[8] * 256 + b[9]);
num[4] = (uint)(b[10] * 65536 + b[11] * 256 + b[12]);
num[5] = (uint)(b[13] * 65536 + b[14] * 256 + b[15]);
// Conversion of the numbers into a system using a base of 64
n = 2;
int pos = 0;
for (i = 0; i < 6; i++)
{
cv_to_64(num[i], ref str, pos, n);
pos += n; n = 4;
}
return new String(str);
}