【问题标题】:Bruteforce Attack Project蛮力攻击项目
【发布时间】:2013-05-11 09:08:43
【问题描述】:

我正在为一个项目(与学校无关)创建一个简单的“蛮力攻击”。有人可以告诉我代码的哪一部分出错导致这些错误。

代码:

#include <string>
using namespace std;
//Password array
std::string passwordArray;
//Lowercare character array
std::string lower = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", 
"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
//Uppercase character array
std::string upper = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", 
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
//Digits array
std::string digits = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };

private void setupCharArray()
{
   if (ckhLower.Checked)
{
   characterArray.AddRange(lower);
}

if (chkUpper.Checked)
{
  characterArray.AddRange(upper);
}

if (chkDigits.Checked)
{
  characterArray.AddRange(digits);
}
}

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
  brute();
}

所以我尝试使用 MinGW 编译这段代码

g++ bruteforce.cpp -o bruteforce.exe

我收到这些错误消息

c:\Users\Lotty Playle\Documents>g++ bruteforce.cpp -o bruteforce.exe
bruteforce.cpp:7:66: error: in C++98 'lower' must be initialized by constructor,
not by '{...}'
bruteforce.cpp:7:66: error: could not convert '{"a", "b", "c", "d", "e", "f", "g
", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w
", "x", "y", "z"}' from '<brace-enclosed initializer list>' to 'std::string {aka
std::basic_string<char>}'
bruteforce.cpp:10:66: error: in C++98 'upper' must be initialized by constructor
, not by '{...}'
bruteforce.cpp:10:66: error: could not convert '{"A", "B", "C", "D", "E", "F", "
G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "
W", "X", "Y", "Z"}' from '<brace-enclosed initializer list>' to 'std::string {ak
a std::basic_string<char>}'
bruteforce.cpp:12:73: error: in C++98 'digits' must be initialized by constructo
r, not by '{...}'
bruteforce.cpp:12:73: error: could not convert '{"0", "1", "2", "3", "4", "5", "
6", "7", "8", "9"}' from '<brace-enclosed initializer list>' to 'std::string {ak
a std::basic_string<char>}'
 bruteforce.cpp:14:1: error: expected unqualified-id before 'private'

如果有人知道我做错了什么,请告诉我。

长×

【问题讨论】:

    标签: c++ brute-force


    【解决方案1】:

    字符串数组应如下所示:(使用[]

    std::string lower[] = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", 
    "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
    

    std::string 的字符如下所示:

    std::string lower = "abcdefghijklmnopqrstuvwxyz";
    

    请注意,使用一堆std::strings 来表示字符是非常低效的。您应该使用 char 数组,或者只使用 ascii 算法。

    【讨论】:

    • 谢谢!我不敢相信我以前没有意识到这一点。 :)
    • 但请注意,语言定义不需要实现使用ASCII,有些系统不需要。
    • @PeteBecker 你碰巧知道 bruteforce.cpp:14:1: error: expected unqualified-id before 'private' 是什么意思吗?
    • @charlotteplayle - 其他几个错误消息可能意义不大。之前的错误可能意味着代码没有意义。或者即使它在其他方面是有效的,编译器也必须猜测一个合理的延续,并且可能没有猜对。所以修复早期的错误,看看是否修复了后面的错误。也就是说,private 关键字只能在类定义中使用,而这里不是这种情况。此外,它后面应该跟一个:
    猜你喜欢
    • 2011-06-10
    • 1970-01-01
    • 1970-01-01
    • 2011-06-01
    • 2013-05-28
    • 2021-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多