473,378 Members | 1,122 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

YENC Algorithm JPG

I'm trying to get a Yenc Decoding algorithm working but keep getting the
same problem. I'm using data from the yenc test newsgroup and have tried the
same thing with most of the example source code on sourceforge etc. with
multiple different posts and I keep getting the same problem - the post I'm
trying to decode has an encoded JPG file (a film poster for Kill Bill 2)
which the yEnc tools like yEnc.EXE manage to decode and encode fine, but
when I run my c# decoder I get weird intermittant translation issues.

My code looks like this (and is the same algorithm as almost everyone I've
seen irrespective of the language).

private byte[] YencDecode(byte[] encodedBlock)
{
ArrayList resultBlock = new ArrayList();
bool escape = false;
for(int count = 0; count < encodedBlock.Length ; count++)
{
byte character = encodedBlock[count];
bool conversionComplete = false;
switch(character)
{
case 61: // =
escape = true;
break;
default:
unchecked
{
if (escape)
{
character -= 64;
}
character -= 42;
}
escape = false;
conversionComplete = true;
break;
}
if(conversionComplete )
{
resultBlock.Add(character);
}
}
return (byte[])resultBlock.ToArray(typeof(byte));
}

The problem is that the 26th byte of the particular post I'm playing with is
originally 34 which decodes using this algorithm to 248, however this is
decoded by the yEnc program to 120. In fact every byte which is
mistranslated by my code above in comparisom to the yEnc program is out by
either 128 or -128 which corrupts the JPG. Clearly theres some magic number
at play here which I just don't understand. About 5% of my bytes are
suffering from this problem, (all the rest are identical to those produced
by yEnc.exe) and its unrelated to the yencode "escape" character of "=" or
line breaks, as the first instance is only 26 bytes in and is unescaped. I'm
generating my byte array by cutting out the yencoded block and using
System.Text.ASCIIEncoding.ASCII.GetBytes(string).

I know JPGs are BigEndian but frankly, I've no idea if this is related to my
problem at all, or where I should apply UnicodeBigEndian translation, or
whether thats a complete red herring.

Can anyone help ?

Thanks,
Phillip
Jul 21 '05 #1
2 1959
Phillip Hamlyn <re****************@hamlyn.demon.co.uk> wrote:

<snip>
I'm generating my byte array by cutting out the yencoded block and
using System.Text.ASCIIEncoding.ASCII.GetBytes(string).


That's almost certainly the problem - one of the defining features (as
far as I can see) of yEnc is that it *doesn't* just use ASCII.

You'll need to get the raw bytes of the message, as returned by the
server, not the decoded text form.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2
Jon,

Thanks for the reply. I found I was reading from the NNTP NetworkStream and
returing String by using ASCII Encoding, which I thought was correct (cos
NNTP was an ASCII based protocol), but of course then layered over it the
ability to read yEnc - which as you point out is not strictly ASCII. Of
course my earlier uuEncode worked because it accepts the encoding bulk of
being strictly ASCII compatible but yEnc tries to be clever.

I fixed it by treating all NNTP content as a byte array until I needed to
parse it (for "=ybegin" for instance) whereby I converted it on the fly.

Thanks for the pointing me in the right direction.

Phillip
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Phillip Hamlyn <re****************@hamlyn.demon.co.uk> wrote:

<snip>
I'm generating my byte array by cutting out the yencoded block and
using System.Text.ASCIIEncoding.ASCII.GetBytes(string).


That's almost certainly the problem - one of the defining features (as
far as I can see) of yEnc is that it *doesn't* just use ASCII.

You'll need to get the raw bytes of the message, as returned by the
server, not the decoded text form.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Freddie | last post by:
Hi, I posted a while ago for some help with my word finder program, which is now quite a lot faster than I could manage. Thanks to all who helped :) This time, I've written a basic batch...
5
by: Marvin Grill | last post by:
Hi, I'm working on a type of NewsHound program and am stuck on how to decode the yEnc encoded articles (body). I tried using Joe Feser's yEnc class but can't seem to get it to work properly Not...
2
by: Phillip Hamlyn | last post by:
I'm trying to get a Yenc Decoding algorithm working but keep getting the same problem. I'm using data from the yenc test newsgroup and have tried the same thing with most of the example source code...
6
by: Scirious | last post by:
People, many of you may not know what yEnc is. To simplify, it is a methode to encode binary files very used in Usenet because it creates an overhead of only 2% when compare to 33%-40% of overhead...
1
by: Kairo Matthias | last post by:
How can i encode with yEnc?
0
by: BiT | last post by:
Hi, I'm working on a newsgroup program and stuck on how to decode the yEnc encoded articles (body). i've found this dll of yenc32 - yDecLib.dll in https://sourceforge.net/projects/yenc32/ but...
6
by: Extremest | last post by:
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...
2
by: John Savage | last post by:
I save posts from a midi music newsgroup, some are encoded with yenc encoding. This gave me an opportunity to try out the decoders in Python. The UU decoder works okay, but my YENC effort gives...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.