P
Phillip Hamlyn
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
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