🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #62139

Re: UUdecoding question

#62139
From: MrMxyzptlk
Date: Wed, 27 Nov 2002 12:06
98 lines
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/


Technical Details
Message-ID: <LxOdnZvGja5xKHmgXTWcpw@giganews.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!logbridge.uoregon.edu!nntp-relay.ihug.net!ihug.co.nz!west.cox.net!cox.net!nntp2.aus1.giganews.com!nntp.giganews.com!nntp3.aus1.giganews.com!news.giganews.com.POSTED!not-for-mail
References: <PcycndP5r-WJsnmgXTWcoA@giganews.com> <20021126231315.491$FH@newsreader.com>

Show Full Headers
Complete Article Headers
Message-ID: <LxOdnZvGja5xKHmgXTWcpw@giganews.com>
Subject: Re: UUdecoding question
Date: Wed, 27 Nov 2002 07:06:44 -0500
From: "MrMxyzptlk" <yaya@hotmail.com>
References: <PcycndP5r-WJsnmgXTWcoA@giganews.com> <20021126231315.491$FH@newsreader.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!logbridge.uoregon.edu!nntp-relay.ihug.net!ihug.co.nz!west.cox.net!cox.net!nntp2.aus1.giganews.com!nntp.giganews.com!nntp3.aus1.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Wed, 27 Nov 2002 06:09:15 -0600
Newsgroups: news.software.nntp
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
Lines: 97
X-Trace: sv3-EvBS6AoBz2Ke6EfIXokESE93PUSWQb5l5Q9pzFxqHpnB17XBs70xmx5JZ5jZweDOPHvqI7czShMZDFd!fk3OuT46gOgezCPtUZtElPpGo2kX8sPJ+/5viC9zocdq7K3pqZSFPp1H41c=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.1