473,699 Members | 2,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Le ngth ; count++)
{
byte character = encodedBlock[count];
bool conversionCompl ete = false;
switch(characte r)
{
case 61: // =
escape = true;
break;
default:
unchecked
{
if (escape)
{
character -= 64;
}
character -= 42;
}
escape = false;
conversionCompl ete = true;
break;
}
if(conversionCo mplete )
{
resultBlock.Add (character);
}
}
return (byte[])resultBlock.To Array(typeof(by te));
}

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.ASC IIEncoding.ASCI I.GetBytes(stri ng).

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 UnicodeBigEndia n translation, or
whether thats a complete red herring.

Can anyone help ?

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

<snip>
I'm generating my byte array by cutting out the yencoded block and
using System.Text.ASC IIEncoding.ASCI I.GetBytes(stri ng).


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.co m>
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.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Phillip Hamlyn <re************ ****@hamlyn.dem on.co.uk> wrote:

<snip>
I'm generating my byte array by cutting out the yencoded block and
using System.Text.ASC IIEncoding.ASCI I.GetBytes(stri ng).


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.co m>
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
2357
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 binary usenet poster in Python, but encoding the data into yEnc format is fairly slow. Is it possible to improve the routine any, WITHOUT using non-standard libraries? I don't want to have to rely on something strange ;)
5
369
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 sure whether it's an Encoding.Type problem or not getting the stream start position right. In any case here's part of the code with the problem:
2
2061
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 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...
6
6840
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 created by other methos such as UUencode, base64... However, every code example I so was in C and using unsigned numbers. Actually, I've found one example in Java, but just for decode, not for encode. Are there anyone who knows how to help me?...
1
1526
by: Kairo Matthias | last post by:
How can i encode with yEnc?
0
1062
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 when i try to add it to my project i get error message: please make sure that the file is accessible, and that it is a valid assembly or COM component. dose any1 kow source code or dll file of function to decode yenc?
6
2244
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 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.
2
2174
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 results unexpected: import yenc, sys fd1=open(sys.argv,'r') #yenc.encode(sys.argv,"outfile.yenc",bytes=0) yenc.decode(sys.argv,"outfile.mid",bytes=0,crc_in='')
0
8691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8620
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9038
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8920
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7755
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6536
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
2351
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2012
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.