473,748 Members | 5,232 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 1989
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
2363
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
2064
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
6845
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
1528
by: Kairo Matthias | last post by:
How can i encode with yEnc?
0
1066
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
2247
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
2179
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
8831
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
9374
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
6796
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...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4876
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
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.