Thread View: news.software.nntp
3 messages
3 total messages
Started by MrMxyzptlk
Wed, 27 Nov 2002 02:31
UUdecoding question
Author: MrMxyzptlk
Date: Wed, 27 Nov 2002 02:31
Date: Wed, 27 Nov 2002 02:31
47 lines
2536 bytes
2536 bytes
Ok I have used the code below and passed in a line at time from a uuencoded
message. (stripped of blank lines, begin and end lines and, the leading M
removed)
Now what? I tried writing the lines out in a binary format and a text format
but the files are unusable.
For example say I decode a jpg, when I open the file there is no image.
Can anyone guide me a little more?
Thank you for your time, Anthony.
*****************************************************************
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;
}
Re: UUdecoding question
Author: Curt Welch
Date: Wed, 27 Nov 2002 04:13
Date: Wed, 27 Nov 2002 04:13
85 lines
3987 bytes
3987 bytes
"MrMxyzptlk" <yaya@hotmail.com> wrote:
> Ok I have used the code below and passed in a line at time from a
> uuencoded message. (stripped of blank lines, begin and end lines and, the
> leading M removed)
I wouldn't throw the M away. I'd use it instead of trusting the line
length to be correct. But for a properly formated line I guess it doesn't
make much difference. But it would be good to check to make sure the two
match.
> Now what? I tried writing the lines out in a binary format and a text
> format but the files are unusable.
>
> For example say I decode a jpg, when I open the file there is no image.
Find a uudecode tool that works. Compare what it produces to what your
code produces. Fix whatever is wrong.
> Can anyone guide me a little more?
>
> Thank you for your time, Anthony.
What language is this?
> *****************************************************************
>
> public string uuDecode(string sBuffer)
>
> {
>
> string str1=String.Empty;
>
> int j = sBuffer.Length ;
>
> for (int i = 1; i <= j; i += 4)
The last line won't have a length that's a multiple of 4, so you need to do
more testing. That that will only cause your code to add 1 or 2 extra
bytes so that won't prevent a jpg from viewing.
And as a matter of style, the Substring() function uses a 0 based index, so
it's silly to start the loop here at 1. It's cleaner if you write:
for (i = 0; i < j; i += 4)
and then use i, i+1, i+2 and i+3, instead of i-1, i, i+1, i+2 like you
do below.
> {
>
> 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)));
You can't just subtract 32 from the character to get the 6 bit value. You
have to take only the low 6 bits. i.e., do an AND operation with 63 after
subtracting 32. (or mod 64).
The orginal uuencode would map nulls to spaces. But some text programs
will strip trailing spaces from lines which would break most uudecoding
programs. So, common practice today is to use ` for NULL instead of space
which works fine as long as you ignore the higher bits.
> 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;
>
> }
The rest of the shifting and adding look correct - assuming your
Convert.ToChar stuff always produces a postive number from 0 to 255.
--
Curt Welch http://CurtWelch.Com/
curt@kcwc.com Webmaster for http://NewsReader.Com/
Re: UUdecoding question
Author: MrMxyzptlk
Date: Wed, 27 Nov 2002 12:06
Date: Wed, 27 Nov 2002 12:06
98 lines
4579 bytes
4579 bytes
This is C#, thank you for your help.
Anthony.
"Curt Welch" <curt@kcwc.com> wrote in message
news:20021126231315.491$FH@newsreader.com...
> "MrMxyzptlk" <yaya@hotmail.com> wrote:
> > Ok I have used the code below and passed in a line at time from a
> > uuencoded message. (stripped of blank lines, begin and end lines and,
the
> > leading M removed)
>
> I wouldn't throw the M away. I'd use it instead of trusting the line
> length to be correct. But for a properly formated line I guess it doesn't
> make much difference. But it would be good to check to make sure the two
> match.
>
> > Now what? I tried writing the lines out in a binary format and a text
> > format but the files are unusable.
> >
> > For example say I decode a jpg, when I open the file there is no image.
>
> Find a uudecode tool that works. Compare what it produces to what your
> code produces. Fix whatever is wrong.
>
> > Can anyone guide me a little more?
> >
> > Thank you for your time, Anthony.
>
> What language is this?
>
> > *****************************************************************
> >
> > public string uuDecode(string sBuffer)
> >
> > {
> >
> > string str1=String.Empty;
> >
> > int j = sBuffer.Length ;
> >
> > for (int i = 1; i <= j; i += 4)
>
> The last line won't have a length that's a multiple of 4, so you need to
do
> more testing. That that will only cause your code to add 1 or 2 extra
> bytes so that won't prevent a jpg from viewing.
>
> And as a matter of style, the Substring() function uses a 0 based index,
so
> it's silly to start the loop here at 1. It's cleaner if you write:
>
> for (i = 0; i < j; i += 4)
>
> and then use i, i+1, i+2 and i+3, instead of i-1, i, i+1, i+2 like you
> do below.
>
> > {
> >
> > 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)));
>
> You can't just subtract 32 from the character to get the 6 bit value. You
> have to take only the low 6 bits. i.e., do an AND operation with 63 after
> subtracting 32. (or mod 64).
>
> The orginal uuencode would map nulls to spaces. But some text programs
> will strip trailing spaces from lines which would break most uudecoding
> programs. So, common practice today is to use ` for NULL instead of space
> which works fine as long as you ignore the higher bits.
>
> > 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;
> >
> > }
>
> The rest of the shifting and adding look correct - assuming your
> Convert.ToChar stuff always produces a postive number from 0 to 255.
>
> --
> Curt Welch
http://CurtWelch.Com/
> curt@kcwc.com Webmaster for
http://NewsReader.Com/
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads