?? xx.cpp
字號:
// Created:11-03-98
// By Jeff Connelly
// XXEncoding, similar to UUEncoding.
// XXE should be used instead of UUE because the alphabet is + and - 0-9, A-Z,
// and a-z. The problems of translation from ASCII to other is fixed in XXE.
#include "stdafx.h"
#define EXPORTING
#include "comprlib.h"
#define ENC(c) (set[(c) & 077])
// Character set
static char set[] =
"+-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
// Output a group of 3 bytes pointed to by 'p'
static void outenc(char* p)
{
int c1, c2, c3, c4;
c1 = *p >> 2;
c2 = (*p << 4) & 060 | (p[1] >> 4) & 017;
c3 = (p[1] << 2) & 074 | (p[2] >> 6) & 03;
c4 = p[2] & 077;
write_byte(ENC(c1));
write_byte(ENC(c2));
write_byte(ENC(c3));
write_byte(ENC(c4));
}
static int fr(char* buf, int cnt)
{
int c, i;
for (i = 0; i < cnt; ++i)
{
c = read_byte();
if (end_of_data())
return i;
buf[i] = c;
}
return cnt;
}
// Single character decoding
#define DEC(c) (table[(c) & 0177])
static char table[128];
static int replace;
// XXEncode to plain text
void xx_encode()
{
char buf[80];
int i, n;
while (true)
{
// Read a 1 to 45 character line
n = fr(buf, 45);
write_byte(ENC(n));
for (i = 0; i < n; i += 3)
outenc(&buf[i]);
write_byte('\n');
if (n <= 0)
break;
}
}
static void outdec(char* p, int n)
{
int c1, c2, c3;
c1 = DEC(*p) << 2 | DEC(p[1]) >> 4;
c2 = DEC(p[1]) << 4 | DEC(p[2]) >> 2;
c3 = DEC(p[2]) << 6 | DEC(p[3]);
if (n >= 1)
write_byte(c1);
if (n >= 2)
write_byte(c2);
if (n >= 3)
write_byte(c3);
}
// Decode XXEncoded file
void xx_decode()
{
char buf[80];
char* bp;
int n, i;
bp = table;
for (n = 128; n; --n)
*(bp++) = 0;
bp = set;
for (n = 64; n; --n)
table[*(bp++) & 0177] = 64 - n;
while (true)
{
// Read an input line
for (i = 0; i < sizeof(buf); ++i)
{
buf[i] = read_byte();
if (end_of_data())
break;
}
n = DEC(buf[0]);
if (n <= 0)
break;
bp = &buf[1];
while (n > 0)
{
if (replace)
outdec(bp, n);
bp += 4;
n -= 3;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -