From e527c45c2d9797e4c6d151ba0447d88c30a08f74 Mon Sep 17 00:00:00 2001 From: hooper114 Date: Thu, 22 Jan 2009 22:25:12 +0000 Subject: [PATCH] Correction to Base256 encoding --- backend/dm200.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/backend/dm200.c b/backend/dm200.c index be089a2e..20cf7157 100644 --- a/backend/dm200.c +++ b/backend/dm200.c @@ -382,20 +382,26 @@ char ecc200encode(unsigned char *t, int tl, unsigned char *s, int sl, char *enco case 'b': // Binary { int l = 0; // how much to encode + int temp; if (encoding) { int p; for (p = sp; p < sl && tolower(encoding[p]) == 'b'; p++) l++; } t[tp++] = 231; // base256 - if (l < 250) - t[tp++] = l; - else { - t[tp++] = 249 + (l / 250); - t[tp++] = (l % 250); + if (l < 250) { + t[tp] = l + (((tp + 1) * 149) % 255) + 1; tp++; + } else { + t[tp] = (249 + (l / 250)) + (((tp + 1) * 149) % 255) + 1; tp++; + t[tp] = (l % 250) + (((tp + 1) * 149) % 255) + 1; tp++; } while (l-- && tp < tl) { - t[tp] = s[sp++] + (((tp + 1) * 149) % 255) + 1; // see annex H + temp = s[sp++] + (((tp + 1) * 149) % 255) + 1; // see annex H + if(temp <= 255) { + t[tp] = temp; + } else { + t[tp] = temp - 256; + } tp++; } enc = 'a'; // reverse to ASCII at end