Ahoj,
mam generator slov. Chcem si vyskusat, ako dlho by mi trval brute force na moj zasifrovany subor. Pouzivam Linux (Ubuntu 10.11). Subor som zasifroval pomocou openssl:
echo 4563 | openssl des -in cisty_text -out mesage -pass stdin
-in subor ktory posielam na sifrovanie
-out je zasifrovany subor
-pass stdin - nastavi heslo 4563 (v tomto pripade)
Ked chcem desifrovat pred -in sa da prepinac -d
Program mi vzdy skonci hned na prvom pokuse s chybou Floating point exception a neviem najst chybu.
Pravdepodobne mi to vzdy spadne na return_code = system(command);
Vopred Dakujem za vsetky rady.
#include <iostream>
#include <fstream>
#include <sstream>
#include <math.h>
#include <time.h>
#include <pthread.h>
#include <stdlib.h>
#define time_interval 10
using namespace std;
unsigned long word_counter = 0; //pocitadlo vygenerovanych hesiel
char allowed_characters[] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}; //znaky pre generovanie hesla
int max_password_lenght = 5;
int size_of_allowed_characters = sizeof(allowed_characters) / sizeof(char);
time_t start_time;
pthread_t vlakno1, vlakno2;
int v1, v2;
int return_code;
unsigned long all_possible_passwords_count(){
unsigned long total_passwords = 0;
int password_size = max_password_lenght;
for (int i = password_size; i > 0; i--){
total_passwords += pow(size_of_allowed_characters, password_size);
password_size--;
}
return total_passwords;
}
void * trace_to_file(void *txt){
while ((int *)txt){
ofstream trace;
trace.open("trace.txt", ios::app);
unsigned long total = all_possible_passwords_count();
trace << "Total: " << total << " words" << endl;
trace << "Used (generated): " << word_counter << " words" << endl;
trace << "To end: " << total - word_counter << " words" << endl;
//ziskat cas
time_t current_time;
current_time = time(NULL);
//cas od zaciatku
trace << "Time from start: " << current_time - start_time << " seconds" << endl;
unsigned long finish = (total * (current_time - start_time)) / (word_counter);
trace << "Total time to finish (presumption): " << finish << " seconds" << endl;
trace << "--------------------------------------------" << endl;
trace.close();
sleep(time_interval);
}
}
void generate_next_word (string word){
if (word.length() <= max_password_lenght){
cout << "Test for password: " << word << endl;
string pass = "echo " + word + " | openssl des -d -in message -out de_mesage -pass stdin";
const char *command = pass.c_str();
cout << command << endl;
return_code = system(command);
if (return_code == 0){
cout << "OK password is: " << endl;
exit(0);
}
else if (return_code != 0) {
word_counter++;
string new_word;
for (int i = 0; i < size_of_allowed_characters; i++){
string add_character;
add_character = allowed_characters[i];
new_word = word + add_character;
generate_next_word(new_word);
}
}
}
}
void * call_start(void *txt){
for (int i = 0; i < size_of_allowed_characters ; i++){ //-lpthread
string word;
word = allowed_characters[i];
generate_next_word(word);
}
exit(0);
}
int main(){
start_time = time(NULL);
char pokus1[] = "text";
v1 = pthread_create( &vlakno1, NULL, &call_start, (void*)&pokus1);
int param = v1;
v2 = pthread_create( &vlakno2, NULL, &trace_to_file, (void*)¶m);
pthread_join(vlakno2, NULL);
//exit(0);
}