xor.cpp

来自「非常好用的五子棋游戏源码」· C++ 代码 · 共 44 行

CPP
44
字号
// Created:10-21-98
// By Jeff Connelly

// XOR encryption

// Justs XOR the file with the password, simple and fast
// Very weak!

// Used in the ARC archiver

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

static void xor_crypt(char* pw);

// Encrypt using XOR
void EXPORT xor_encode(char* pw)
{
    xor_crypt(pw);
}

// Decrypt using XOR
void EXPORT xor_decode(char* pw)
{
    xor_crypt(pw);
}

// Used for both encryption and decryption
static inline void xor_crypt(char* pw)
{
    register char c;
    register int i = 0;
    register int pwlen = strlen(pw);

    while (!end_of_data())
    {
        c = read_byte();
        write_byte(c ^ pw[i % pwlen]);
        ++i;
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?