⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xxe.cpp

📁 非常好用的五子棋游戏源码
💻 CPP
字号:
// Created:10-24-98
// By Jeff Connelly

// XXEncoding/Decoding

// This should be used instead of UUEncoding because the problems of
// ECBDIC -> ASCII translation is fixed.  XXE is newer than UUE, and not
// as popular yet.

// Look in ORIGSRC\XXENCODE.C and ORIGSRC\XXDECODE.C for the original code

#include "stdafx.h"
#define EXPORTING
#include "comprlib.h"

// Encode a character
#define ENC(c)  (set[(c) & 077])

// This set of characters is used
static char set[] =
    "+-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

// Output one 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));
}

// 'fr' is like 'read'
static int fr(char* buf, int cnt)
{

    register int i, c;

    for (i = 0; i < cnt; ++i)
    {
        c = read_byte();
        if (end_of_data())
            return i;
        buf[i] = c;
    }

    return cnt;
}


// XXEncode a file
void EXPORT 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;
    }
}

#define DEC(c) (table[(c) & 0117])
static char table[128];
static int replace;

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);
}

void EXPORT 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++) & 0117] = 64 - n;

    while (true)
    {
        // Read an inpt 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 + -