uudecode


public static byte[] uuDecode(string sBuffer)
{
  // Create an output array
  byte[] outBuffer = new byte[(sBuffer.Length-1)/4*3];
  int outIdx = 0;

  // Get the string as an array of ASCII bytes
  byte[] asciiBytes = Encoding.ASCII.GetBytes(sBuffer);

  for (int i=0; i<asciiBytes.Length; i++)
    asciiBytes[i] = (
byte)((asciiBytes[i]-0x20) & 0x3f);



  // Convert each block fo 4 input bytes into 3
  // output bytes
  for (int i = 1; i <= (asciiBytes.Length-1); i += 4)
  {
    outBuffer[outIdx++] = (
byte)(asciiBytes[i] << 2 | asciiBytes[i+1] >> 4);
    outBuffer[outIdx++] = (
byte)(asciiBytes[i+1] << 4 | asciiBytes[i+2] >> 2);
    outBuffer[outIdx++] = (
byte)(asciiBytes[i+2] << 6 | asciiBytes[i+3]);
  }

  return
outBuffer;
}




There you go; next time you’re writing a Usenet news reader, you’ll have somewhere to copy the uudecode function from.


Source code looks so much better in colour doesn’t it?


(This is a fixed version of the source; thanks to Esa Leskinen for pointing out that my previous version was incomplete).