首页 > 编程语言 > 详细

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

时间:2015-05-05 21:20:44      阅读:256      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!