C++Builder Why You Should Know About Brute Force Methods in C++

FireWind

Свой
Регистрация
2 Дек 2005
Сообщения
1,957
Реакции
1,199
Credits
4,009
Why You Should Know About Brute Force Methods in C++
By Yilmaz Yoru November 29, 2021

What is Brute Force Method? How we can use Proof By Exhaustion Method? What are Proof by Case and Proof by Analysis? How we can code Brute Force Method in C++? How we can prevent our servers from Brute Force Attacks?

What is the Brute Force Method?​

Для просмотра ссылки Войди или Зарегистрируйсяis a method of mathematical proof in which the statement to be proved is split into a finite number of cases or sets of equivalent cases, these each unique cases are checked to see if the proposition in question holds in all cases, if all case variations satisfy then we can say all is provided and this statement is true or false. The Brute Force Method also known as proof by exhaustion, proof by cases, proof by case analysis, complete induction.

The Brute Force is a method of Для просмотра ссылки Войди или Зарегистрируйся and contains two stages,

  1. A proof that the set of cases is exhaustive (i.e. each instance of the statement to be proved matches the conditions of one of the cases) .
  2. A proof of each of the cases

What is the Brute Force Method used for?​

Computational technology brings high speed and a lot of good things to calculate many cases in problems. The Brute Force method can be used to check all variations in these kind of problems. In general, in a Brute Force Method there is no limit but in usage there is a limit in most cases. For example all moves in some games (tic-tac-toe, chess, go, etc.) can be checked in limits of movement depth, otherwise there are a lot of variations to check each moves. This may cost a lot of time to calculate moves. Because of this, we have better methods to calculate this kind of games. Genetic Algorithms, Fuzzy Logic, Branch Tree Methods, ANN CNN , RNN and other methods of AI Technologies. But note that this method is robust than any other methods, because all variations are checked. Other methods are faster and very successful but remember that they also neglects some moves in some depths

What is the dark side of the Brute Force Method?​

Computer technology can also bring some bad things like Brute-Force Attacks in Cryptography, This is known as an Exhaustive Key Search. The Brute Force Attack consists of an attacker submitting many cases (i.e passwords or passphrases) with the hope to find a case which is satisfying or dissatisfying the condition. In an example, the attacker systematically checks all possible passwords and passphrases until the correct one is found. Alternatively, the attacker can attempt to guess the key which is typically created from the password using a key derivation function. Today servers, databases and many applications area capable to reject after few attempts failed to prevent these kind of attacks.

Is a Brute Force Attack always a bad thing?​

Brute Force Attacks can be used in good ways too. For example if you have very important old code files zipped and you want to use them but you don’t remember the password. You can use this method to bring them back. Knowing unsafe parts of your systems or apps are also good to make more secure systems. You can check your system vulnerability against those Brute Force attacks.

C++ is a great programming language with a fast execution time. You can try many variations in all problems in few seconds by using the Brute Force Methods. The function of a Brute Force Method is a recursive function that branches to each variations. Here is a very simple Brute Force Method to generate different text variations.
C++:
// characters to be used in variations
std::string const& brute_chars="abcdefghijklmnopqrstyuz";
 
size_t max_len=5;
 
void brute_force(std::string const& str)
{
 if (str.length() < max_len)
 {
   for (auto ch : brute_chars)
   {
 std::string next = str + ch;
 std::cout << next << '\n';
 brute_force(next);  // recursive call
   }
 }
}
This Brute Force function can be used for 5 character string tests as below,
Код:
#include <iostream>
#include <string>
 
// characters to be used in variations
std::string const& brute_chars="abcdefghijklmnopqrstyuz";
 
size_t max_len=5;
 
void brute_force(std::string const& str)
{
 if (str.length() < max_len)
 {
   for (auto ch : brute_chars)
   {
 std::string next = str + ch;
 std::cout << next << '\n';
 brute_force(next);  // recursive call
   }
 }
 
}
 
int main()
{
  max_len = 5;
  brute_force("");
 
  getchar();
  return 0;
}

What other uses are there for the Brute Force Method?​

This Brute Force function can be used for 1 to 5 character string tests as below,
C++:
#include <iostream>
#include <string>
 
// characters to be used in variations
std::string const& brute_chars="abcdefghijklmnopqrstyuz";
 
size_t max_len=5;
 
void brute_force(std::string const& str)
{
 if (str.length() < max_len)
 {
   for (auto ch : brute_chars)
   {
 std::string next = str + ch;
 std::cout << next << '\n';
 brute_force(next);  // recursive call
   }
 }
 
}
 
int main()
{
  for(int b=1; b<=5; b++)
  {
 max_len = b;
 brute_force("");
  }
 
  getchar();
  return 0;
}
As you see we can use this method to check all variations of problems. Here we checked all characters of maximum 5 length strings. This can be used to do research on diseases, viral variations, on games to test different variations, on creating perfect levels, puzzles, mapping 2D 3D maps and checking our agents, algorithms, functions, methods or for other all good things.