Question

I am creating a simple 'Bruteforce attack' for a project (not school related). Could someone please tell me which part of the code is wrong to get these errors.

The Code:

#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();
}

so I try to compile this code using MinGW

g++ bruteforce.cpp -o bruteforce.exe

and I get these error messages

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'

If anyone knows what I'm doing wrong could they please show me.

L x

Was it helpful?

Solution

An array of strings should look like this: (with [])

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" };

A std::string of characters would look like this:

std::string lower = "abcdefghijklmnopqrstuvwxyz";

Note that using a bunch of std::strings to represent characters is extremely inefficient. You should use a char array, or just work with ascii arithmetic.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top