加密

来源:互联网 发布:笛子的视频软件 编辑:程序博客网 时间:2024/05/06 02:09

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

#define TRUE 1

void TranslateBuffer(char * buffer, unsigned count, string encryptCode)
{
    __asm{
        mov esi, buffer
        mov ecx, count
        mov al, encryptCode

    L1:
        xor [esi], al
        inc esi
        loop L1
    }
}

int main()
{
    const int BUFFERSIZE(200);
    char szBuf[BUFFERSIZE] = "";

    unsigned int count(0);

    string encryptCode("");
    do
    {
        cout << "Please intput the encrypt code:" << endl;
        cin >> encryptCode;
       
        if (encryptCode.size() != 1)
        {
            cout << "Please input one character!" << endl;
            cout << endl;
            cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
        }
        else
        {
            break;
        }
    } while(TRUE);


    ifstream infile("in.txt", ios::binary);
    ofstream outfile1("out1.txt", ios::binary);
    ofstream outfile2("out2.txt", ios::binary);

    while (!infile.eof())
    {
        infile.read(szBuf, BUFFERSIZE);
        count = infile.gcount();
        TranslateBuffer(szBuf, count, encryptCode);
        outfile1.write(szBuf, count);
        TranslateBuffer(szBuf, count, encryptCode);
        outfile2.write(szBuf, count);
    }

    return 0;
}