1. ## Algorithm Help

Hi,

I'm trying to write a decoder for Yenc, the compression algorithm is as follows:

Code:
``` 1. Fetch a character from the input stream.
2. Increment the character's ASCII value by 42, modulo 256
3. If the result is a critical character (as defined in the previous
section), write the escape character to the output stream and increment
character's ASCII value by 64, modulo 256.
4. Output the character to the output stream.
5. Repeat from start.```
So in terms of compression my pseudo code looks something like this:

Code:
```Result = (ASCII+42) % 256
If Result == CriticalValue
WriteOut(CriticalValue)
Result = (CriticalValue + 64) % 256

WriteOut(Result)```
Now for reversal and getting the orignal ASCII code out I have no idea how to approach it as i don't really understand modulo maths, could anyone lend a hand with some reversal pseudo code?

Thanks alot for any help,.

Jack

2. Sorta like what you would do with algebra:
Code:
```ascii = result % 256 - 42;
if ( iscritical(ascii) )
{
WriteOut(ascii);
result = ascii % 256 - 64;
}
WriteOut(result);```

3. result &#37; 256 - 42 can be less than 0
so (because result is between 0 and 255 %256 will have no effect)
the proper way will be

(result - 42 +256)%256