Yenc Help

  • Thread starter Thread starter Extremest
  • Start date Start date
E

Extremest

Does anyone know how to decode a yenc encoded file? I have created a
decoder that seems to work great for text. Now i am trying to create
another one for images and I can't get it to work. I have changed the
encoding on mine and that didn't work and then I tried the only 2 open
source ones I can Find. It is driving me nuts.
 
Does anyone know how to decode a yenc encoded file? I have created a
decoder that seems to work great for text. Now i am trying to create
another one for images and I can't get it to work. I have changed the
encoding on mine and that didn't work and then I tried the only 2 open
source ones I can Find. It is driving me nuts.

It seems to me that "the horse's mouth", so to speak, would be your best
bet:
http://www.yenc.org/

I don't think this newsgroup is a good place for general "yenc-specific"
discussions, but if you've got an issue implementing the format decoder
that relates specifically to your use of C# or .NET, please feel free to
post those questions here.

Pete
 
I think i have the decode part right. The problem seems to maybe be
with the encoding of the string or something. Was wanting some help
on that part of it. The rest should be ok. I have looked at quite
a few decoders and they all do the same thing. My problem is the
encoding of the stream or something.
 
Ok here is my function that goes through the data. I have gotten it
really close just don't know if there is some encoding on a stream
that I am doing wrong or what. Code is rough. Want to get it
working then will clean it up.

static void collect()
{
for (int x = 0; x < msg_ids.Count; x++)
{
Connect();
byte[] buff = new byte[BUFFERSIZE];//buffer for
decoded data.
NetworkStream networkStream = tcpClient.GetStream
();//nntp connection.
StreamReader reader = new StreamReader
(networkStream, Encoding.Default);//reader for nntp connection.
StreamWriter writer = new StreamWriter
(networkStream);//writer for nntp connection.
writer.AutoFlush = true;
int bufferLength = 0;//where we are in the buff
array.
int filelength = 0;//Length of the file from the
header.
string id = msg_ids[x] as string;//The msg_id for
the article.
string line;//Line that is read from the connection.
string fileName;//Name of the file from the header.
id = "body " + id;//build article request.
id = id.Trim();
writer.WriteLine(id);//write article request to nntp
line = reader.ReadLine();//read response from nntp
/*Loop until it finds the beginning of the yenc
data*/
while (reader.Peek() >= 0 && line != null && !
line.StartsWith("=ybegin") &&
!line.StartsWith("begin 644"))
{
line = reader.ReadLine();
if (line == ".")
{
break;
}
}
if (line.StartsWith("begin 644"))//Not implemented
yet.
{
Disconnect();
continue;
}
else
{
if (line == null || line == ".")
{
Disconnect();
continue;
}
fileName = parseForName(line);//get filename
from the header.
string tempsize = parseForString(line,
"size");//get size from the header.
Console.WriteLine(tempsize);
filelength = int.Parse(tempsize);
if (fileName == null)//not valid header.
{
Disconnect();
continue;
}
String partNo = parseForString(line, "part");//
get part # from header.
if (partNo != null)//check and see if there are
more parts or to remove the line from the code.
{
while (line != null && !line.StartsWith
("=ypart"))
{
line = reader.ReadLine();
Console.WriteLine("--{0}--", line);
}
if (line == null)
throw new IOException("Error while
handling a multipart reader. Could not locate line starting with
\"=ypart\".");
}
// Decode the file
line = reader.ReadLine();//read first line of
encoded data.
while (line != null && !line.StartsWith
("=yend"))//will go to end of encoded data.
{
for (int lcv = 0; lcv < line.Length;
lcv++)//go through line by char.
{
if (line[lcv] == '=')//find escape char.
{
lcv++;
if (line[lcv] < 106)//used for the
mod
{
int ts = 106 - line[lcv];
ts = 256 - ts;
buff[bufferLength] = (byte) ts;
bufferLength++;
}
else
{
buff[bufferLength] = (byte)
((line[lcv] - 64) - 42);
bufferLength++;
}
}
else
{
if (line[lcv] < 42)//used for the
mod
{
int ts = 42 - line[lcv];
ts = 256 - ts;
buff[bufferLength] = (byte) ts;
bufferLength++;
}
else
{
buff[bufferLength] = (byte)
(line[lcv] - 42);
bufferLength++;
}
}
}
line = reader.ReadLine();//read next line
for the loop.
}
}
if (bufferLength > 0)//check to see if we decoded
anything if so then write it to a file.
{
FileStream fs = File.Create(fileName);
BinaryWriter bw = new BinaryWriter
(fs,Encoding.Default);
bw.Write(buff,0,filelength);
bw.Close();
fs.Close();
}
}
}
 
Ok here is my function that goes through the data. I have gotten it
really close just don't know if there is some encoding on a stream
that I am doing wrong or what. Code is rough. Want to get it
working then will clean it up.

All due respect, it's not really clear what you expect. Are you thinking
that someone will read through your code and discover an error in the
basic logic of your yenc implementation? If so, I think you're being too
optimistic.

If there is something specific to how you're using C# and/or .NET in your
implementation that you have a question about, this is an appropriate
forum. But I wouldn't say that it's very likely you're going to find
anyone who would just review your code for random bugs, especially for a
task of relatively marginal popularity like a yenc implementation.

If you expect help here, you need to be asking more specific questions
than just "here's my code, what's wrong with it?"

Pete
 
I was mainly asking if anyone knew if the encoding of the streams
was right? I have managed to get uudecoding done with those streams
using php in c# and when I try to do yenc decoding a come up with
only a couple of bytes that are not right when comparing to the same
picture already downloaded with another program.
 
Back
Top