码迷,mamicode.com
首页 > 编程语言 > 详细

C++内嵌汇编代码,简单文件加密

时间:2015-05-05 21:21:44      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char* argv[]){
    if(argc < 3){
        cout<<"Usage: Project infile outfile"<<endl;
        return -1;
    }
    const int BUFSIZE = 2000;
    char buf[BUFSIZE];
    unsigned int count;    // char count
    unsigned int encryptMask;
    cout<<"Encryption code[0-255]?";
    cin>>encryptMask;
    if(encryptMask<0 || encryptMask > 255){
        cout<<"between 0 and 255."<<endl;
        return -1;
    }    
    unsigned char encryptCode = (unsigned char)encryptMask;
    ifstream infile(argv[1],ios::binary);
    ofstream outfile(argv[2],ios::binary);

    cout << "Reading "<<argv[1]<<"and createing"<<argv[2]<<endl;
    while(!infile.eof()){
        infile.read(buf,BUFSIZE);
        count = infile.gcount();
        if(count==0)break;
        __asm{
            lea esi, buf
            mov ecx,count
            mov al,encryptCode
L1:
            xor [esi],al
            inc esi
            loop L1
        }
        outfile.write(buf,count);
    }
    infile.close();
    outfile.close();
    return  0;
}

 

C++内嵌汇编代码,简单文件加密

标签:

原文地址:http://www.cnblogs.com/wucg/p/4479942.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!