One of our posters was looking for a C# implementation of uuEncode and uuDecode.
I found some old code and ported it to both VB.NET and C#, along with a Winforms
test harness.
here is the C# code:
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;
}
}
}
Follow the thread and find the download here:
http://www.eggheadcafe.com/forums/ForumPost.asp?ID=3323&INTID=2
Submission Date: 9/23/2005 3:23:34 PM
Submitted By: Peter Bromberg
My Home Page: http://www.eggheadcafe.com