weixin_36575223 2016-11-02 03:47 采纳率: 0%
浏览 761

C++, 一段码如何改成使用thread的代码

我这儿有段C++的小程序,它可以解一个加密文件的密码,两位数的密码,比如说给一个文档加一个两位数的密码,可以使用这个猜出着两位数的密码。我想请教如何将这段码改成使用thread的C++程序

#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

#include "guesser.h"
#include "generator.h"

// Call as "pgm filename"
int main(int argc, char **argv)
{
    if(argc != 2) {
        cout << "Usage: " << argv[0] << " encryptedfile" << endl;
        exit(1);
    }

    // 创建猜想对象并打开加密文件。
    guesser trythis;
    if(!trythis.open(argv[1])) {
        cout << "Unable to read " << argv[1] << endl;
        exit(2);
    }

    // 计算解码次数。
    int nkey = 0;

    // 尝试密码,知道成功打开文件。
    generator gen("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
              "0123456789");
    string outfile = argv[1] + string(".plain");
    while(true) {
        string keyguess = gen.next();
        guesser::guess_t res = trythis.guess(keyguess, outfile);
        if(res == guesser::no || res == guesser::no_but_wrote) {
            if((++nkey & 0xffff) == 0) {
                cout << nkey << " keys; current "
                     << keyguess << endl;
            }
            continue;
        } else if(res == guesser::yes) {
            cout << "The key is " << keyguess << ", " 
                 << nkey << " keys guessed." << endl;
            exit(0);
        } else {
            cout << "Unable to process guess " << keyguess << endl;
            exit(1);
        }
    }
}
  • 写回答

1条回答 默认 最新

  • Eleven 2016-11-03 12:55
    关注

    如何将这段码改成使用thread的C++程序

    你是想将你的解密操作放到一个单独的线程中去吗?_beginthreadex()

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?