/****************************************************************************** * :CueCat (tm) Reader decoding program. * * Copyright (C) 2000 Hal Duston * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANT WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License at http://www.fsf.org/copyleft/gpl.html * * for more details. * * * * :CueCat (tm) is a trademark of Digital:Convergence Corporation. * * * ******************************************************************************/ #include #include int main(int argc, char *arg[]); static ssize_t decode(char *outbuf, const char *inbuf); int main(int argc, char *arg[]) { char inbuf[512]; char outbuf[512]; ssize_t len; while((len = read(STDIN_FILENO, inbuf, sizeof(inbuf))) != 0) { inbuf[len] = '\0'; len = decode(outbuf, inbuf); outbuf[len++] = 7; /* Ring the bell. */ write(STDOUT_FILENO, outbuf, len); } _exit(0); return 0; } static ssize_t decode(char *outbuf, const char *inbuf) { static int index_64[128] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, 62, 63, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, }; static char pad_64[4] = { 0x10, 0x34, 0x0d, 0x03 }; const char *inptr = inbuf; char *outptr = outbuf; int ch = *inptr++; long n; /* Used as three byte integer. */ int i; while(ch != '\0') { if(index_64[ch] < 0) { *outptr++ = ch; ch = *inptr++; } else { n = 0; for(i = 0; i < 4; ++i) { if(isalpha(ch)) { ch ^= 0x20; /* Swap upper/lower case. */ } if(index_64[ch] < 0) { n = n << 6 | pad_64[i]; /* Pad short runs. */ } else { n = n << 6 | index_64[ch]; ch = *inptr++; } } n ^= 0x434343; /* XOR with "ccc". */ *outptr++ = (n >> 16) ? (n >> 16) : '\0'; *outptr++ = (n >> 8 & 0xff) ? (n >> 8 & 0xff) : '\0'; *outptr++ = (n & 0xff) ? (n & 0xff) : '\0'; } } return outptr - outbuf; }