zoukankan      html  css  js  c++  java
  • C++内嵌汇编代码,简单文件加密

    #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;
    }
  • 相关阅读:
    python django day 1
    C# 日常
    C# NPOI使用
    SharpZipLib 压缩ZIP导出
    JSON劫持
    跨站请求伪造CSRF或XSRF
    跨站脚本XSS安全
    会话窃取
    Cookie
    Promise -ES6
  • 原文地址:https://www.cnblogs.com/wucg/p/4479942.html
Copyright © 2011-2022 走看看