yEncoding is fairly straight-froward, as you will see.
The input file is scanned, 42 is added to each value (MOD 256), and copied to the output.
This offset is added so that the values which tend to not occur often in files are shifted
to the position of critical values.
Critical values are values which are not allowed to occur in the body of an article, to
stay compatible with Usenet. These values are 0 (ASCII NUL), 10 (ASCII LF), and 13 (ASCII
CR).
If, after adding 42 to the input value, the result is a critical value then the value
61 (ASCII '=') is sent to the output followed by the critical value + 64. (Note that
because '=' is used here as the escape value it also becomes a critical value that needs
to be escaped).
In pseudo-code:
// initialise //
CRITICAL_VALUES := CR, LF, NUL, =;
o := 1;
// step through input file //
FOR i := 1
TO END_OF_FILE
// read character and add the 42 offset //
temp := input[i];
temp := (temp + 42)
MOD 256;
// check for critical value //
IF temp
ISIN CRITICAL_VALUES
THEN
// critical value, so send '=' to output, followed by value + 64 //
output[o] := '=';
o := o + 1;
output[o] := (temp + 64) MOD 256;
// not a critical value, so copy input to output //
ELSE output[o] := temp;
o := o + 1;
// repeat until finished //
NEXT i;
Note: the input is the original file. The output is the file encoded.
This is exactly like encoding, in reverse.
In pseudo-code:
// initialise //
o := 1;
// step through input file //
FOR i := 1
TO END_OF_FILE
// read character //
temp := input[i];
// check for escape character //
IF temp := '='
THEN
// read next character and subtract 64 //
i := i + 1;
temp := input[i];
temp := (temp - 64) MOD 256;
// subtract the 42 offset and send the result to the output //
temp := (temp - 42)
MOD 256;
output[o] := temp;
o := o + 1;
// repeat until finished //
NEXT i;
Note: the input is the encoded file. The output is the original file.