Hi Leut's,
habe mal ne Frage. Hatte ja, durch Hilfe in diesem Forum nen kleinen Brute-Force-Algorithmus geschrieben. (Nix gefährliches, nur um mal den algorithmus zu verstehen.)
Nebenbei will ich mir auch noch C++ beibringen. Ich wollte nun dieses kleine Programm in C++ nochmal neu schreiben damit ich da nen kleinen Einstieg bekomme.
Ist halt so dass im Code nen Passwort festgelegt ist und das Programm dann halt das PW sucht.
Leider kriege ich einiges noch nicht hin, bzw. kriege ich vom Compiler jede Menge Fehlermeldungen. Könnte von euch vllt. mal jemand drüber gucken und mir sagen was ich da falsch gemacht habe, bzw. was in C++ so nicht geht? Mit den Fehlermeldungen vom Compiler kann ich bis jetzt noch nicht sehr viel anfangen.
IDE ist Netbeans mit C++ PlugIn und CygWin Compiler im Hintergrund, falls das wichtig ist.
In Java funktioniert das Programm tadellos, müsste nur noch nen bissl an der Performace feilen...
Algorithmus in Java:
Algorithmus in C++
Fehlermeldungen:
Danke im voraus.
habe mal ne Frage. Hatte ja, durch Hilfe in diesem Forum nen kleinen Brute-Force-Algorithmus geschrieben. (Nix gefährliches, nur um mal den algorithmus zu verstehen.)
Nebenbei will ich mir auch noch C++ beibringen. Ich wollte nun dieses kleine Programm in C++ nochmal neu schreiben damit ich da nen kleinen Einstieg bekomme.
Ist halt so dass im Code nen Passwort festgelegt ist und das Programm dann halt das PW sucht.
Leider kriege ich einiges noch nicht hin, bzw. kriege ich vom Compiler jede Menge Fehlermeldungen. Könnte von euch vllt. mal jemand drüber gucken und mir sagen was ich da falsch gemacht habe, bzw. was in C++ so nicht geht? Mit den Fehlermeldungen vom Compiler kann ich bis jetzt noch nicht sehr viel anfangen.
IDE ist Netbeans mit C++ PlugIn und CygWin Compiler im Hintergrund, falls das wichtig ist.
In Java funktioniert das Programm tadellos, müsste nur noch nen bissl an der Performace feilen...
Algorithmus in Java:
Java:
package bruteforce;
//~--- JDK imports ------------------------------------------------------------
import java.util.Arrays;
public class BruteForce {
public static char[] hackChar = { 'a' };
public static String hackString = "";
public static int n = 1;
public static char[] password = { 'h', 'a', 'l', 'l', 'o' };
public static boolean isHacked = false;
public static void main(String[] args) {
while ((isHacked == false)) {
hackChar[0] = ' ';
for (int k = 97; k < 123; k++) {
hackChar[0] = (char) k;
hackString = new String(hackChar);
System.out.println(hackString);
isHacked = check(hackChar);
if (isHacked == true) {
System.out.println("Geknackt, das Passwort lautet: " + hackString);
break;
} else {
for (int i = 0; i < hackChar.length; i++) {
if (hackChar[i] == 'z') {
try {
hackChar[i + 1]++;
} catch (Exception e) {
n++;
hackChar = new char[n];
for (int j = 0; j < n; j++) {
hackChar[j] = 'a';
}
}
hackChar[i] = 'a';
}
}
}
}
}
}
public static boolean check(char[] hack) {
if (Arrays.equals(hack, password)) {
isHacked = true;
} else {
isHacked = false;
}
return isHacked;
}
}
Algorithmus in C++
Java:
#include <ios>
#include <stdlib.h>
#include <iostream>
#include <string>
using namespace std;
//globale Variablen
bool isHacked = false;
char hackChar = 'a";
char password[] = 'abc';
string hackString = "";
int n = 1;
/*
* Main-Funktion
*/
int main(int argc, char** argv) {
while (isHacked == false) {
hackChar[0] = ' ';
for (int k = 97; k < 123; k++) {
hackChar[0] = (char) k;
hackString.clear();
hackString.assign(hackChar);
cout << hackString << "\n";
isHacked = check(hackChar);
if (isHacked == true) {
cout << "Geknackt, das Passwort lautet: " << hackString;
break;
} else {
for (int i = 0; i < hackChar.length; i++) {
if (hackChar[i] == 'z') {
try {
hackChar[i + 1]++;
} catch (...) {
n++;
hackChar.clear();
char hackChar[n];
for (int j = 0; j < n; j++) {
hackChar[j] = 'a';
}
}
hackChar[i] = 'a';
}
}
}
}
}
return (EXIT_SUCCESS);
}
/*
* Check-Funktion um ermitteltes Passwort zu prüfen
*/
bool check(char hack[]) {
if (strcmp(hack, password) == 0) {
isHacked = true;
} else {
isHacked = false;
}
return isHacked;
}
Fehlermeldungen:
Code:
Running "C:\cygwin\bin\make.exe -f BruteForce CONF=Debug" in H:\Development\C++\BruteForce
g++ BruteForce.cpp -o BruteForce
BruteForce.cpp:18: error: missing terminating ' character
BruteForce.cpp:19: error: expected primary-expression before "char"
BruteForce.cpp:19: error: expected `,' or `;' before "char"
BruteForce.cpp:19:19: warning: multi-character character constant
BruteForce.cpp: In function `int main(int, char**)':
BruteForce.cpp:29: error: invalid types `char[int]' for array subscript
BruteForce.cpp:32: error: invalid types `char[int]' for array subscript
BruteForce.cpp:34: error: invalid conversion from `char' to `const char*'
BruteForce.cpp:34: error: initializing argument 1 of `std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::assign(const _CharT*) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]'
BruteForce.cpp:36: error: `check' undeclared (first use this function)
BruteForce.cpp:36: error: (Each undeclared identifier is reported only once for each function it appears in.)
BruteForce.cpp:43: error: request for member `length' in `hackChar', which is of non-class type `char'
BruteForce.cpp:44: error: invalid types `char[int]' for array subscript
BruteForce.cpp:46: error: invalid types `char[int]' for array subscript
BruteForce.cpp:49: error: request for member `clear' in `hackChar', which is of non-class type `char'
BruteForce.cpp:56: error: invalid types `char[int]' for array subscript
BruteForce.cpp: In function `bool check(char*)':
BruteForce.cpp:69: error: `bool check(char*)' used prior to declaration
BruteForce.cpp:71: error: `password' undeclared (first use this function)
make: *** [BruteForce] Error 1
Build failed. Exit value 2.
Danke im voraus.
Zuletzt bearbeitet: