Uuencoding is a form of binary-to-text encoding that originated in the Unix program uuencode, for encoding binary data for transmission over the uucp mail system. The name "uuencoding" is derived from "Unix-to-Unix encoding". Since uucp converted characters between various computers' character sets, uuencode was used to convert the data to fairly common characters that were unlikely to be "translated" and thereby destroy the file. The program uudecode reverses the effect of uuencode, recreating the original binary file exactly. uuencode/decode became popular for sending binary files by e-mail and posting to usenet newsgroups, etc. It has now been largely replaced by MIME and yEnc. With MIME, files that might have been uuencoded are transferred with base64 encoding.
//uuEncode and uuDecode
using System;
namespace CSUUCodec
{
public class CSUUCodec
{
public CSUUCodec()
{
}
public string uuDecode(string sBuffer)
{
string str1=String.Empty;
int j = sBuffer.Length ;
for (int i = 1; i <= j; i += 4)
{
str1 = String.Concat(str1, Convert.ToString((char)(((int)Convert.ToChar( sBuffer.Substring ( i-1, 1)) - 32) * 4 + ((int)Convert.ToChar( sBuffer.Substring( i , 1)) - 32) / 16)));
str1 = String.Concat(str1, Convert.ToString((char)(((int)Convert.ToChar( sBuffer.Substring( i , 1)) % 16 * 16) + ((int)Convert.ToChar(sBuffer.Substring( i + 1, 1)) - 32) / 4)));
str1 = String.Concat(str1, Convert.ToString((char)(((int)Convert.ToChar(sBuffer.Substring ( i + 1, 1)) % 4 * 64) + (int)Convert.ToChar( sBuffer.Substring( i + 2, 1)) - 32)));
}
return str1;
}
public string uuEncode(string sBuffer)
{
string str1=String.Empty;
if (sBuffer.Length % 3 != 0)
{
string stuff =new String(' ',3 - sBuffer.Length % 3);
sBuffer = String.Concat(sBuffer, stuff);
}
int j = sBuffer.Length;
for (int i = 1; i <= j; i += 3)
{
str1 = String.Concat(str1, Convert.ToString( (char)( (int)Convert.ToChar(sBuffer.Substring( i-1, 1)) / 4 + 32)));
str1 = String.Concat(str1, Convert.ToString((char)((int)Convert.ToChar(sBuffer.Substring( i-1, 1)) % 4 * 16 + (int)Convert.ToChar(sBuffer.Substring ( i , 1)) / 16 + 32)));
str1 = String.Concat(str1, Convert.ToString((char)((int)Convert.ToChar( sBuffer.Substring ( i , 1)) % 16 * 4 + (int)Convert.ToChar(sBuffer.Substring ( i + 1, 1)) / 64 + 32)));
str1 = String.Concat(str1, Convert.ToString((char)((int)Convert.ToChar( sBuffer.Substring ( i + 1, 1)) % 64 + 32)));
}
return str1;
}
}
}