Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <omp.h>
- #include <openssl/md5.h>
- #include <time.h>
- const char LiteralsLower[] = "abcdefghijklmnopqrstuvwxyz";
- const int NLiteralsLower = sizeof( LiteralsLower ) - 1;
- char HexByteHash[16];
- time_t StartTime, EndTime;
- /* Prototypes */
- static void MD5Hash( const char * );
- static void BruteForce( const int * restrict, const int * restrict, const char *, const int *, int );
- int main()
- {
- const char HashAsString[] = "172522ec1028ab781d9dfd17eaca4427"; // 'david'
- const int *BFOptionSize = &NLiteralsLower;
- const char *BFOption = LiteralsLower;
- int PasswordLength = 6;
- int StrLength = strlen( HashAsString );
- for( int i = 0; i < StrLength / 2 ; i++ )
- {
- if( !sscanf( HashAsString + 2 * i, "%02x", ( unsigned int * ) &HexByteHash[i] ) )
- {
- fprintf( stderr, "FEHLER!!! -> '%s' ist kein Hash-Wert!n", HashAsString );
- exit( EXIT_FAILURE );
- }
- }
- fprintf( stdout, "Hash: %s mit einer Länge von %li Zeichen.n", HashAsString, strlen( HashAsString ) / 2 );
- /* Timer starten */
- time( &StartTime );
- #pragma omp parallel shared( PasswordLength, BFOptionSize )
- for( int PWLength = 0; PWLength < PasswordLength + 1; ++PWLength )
- {
- /* Array-Größe für FstEntry und LstEntry festlegen */
- int FstEntry[PWLength], LstEntry[PWLength];
- /* Array-Felder mit 0 initialisieren */
- for( int j = 0; j < PWLength; ++j )
- FstEntry[j] = LstEntry[j] = 0;
- #pragma omp for schedule( dynamic )
- for( int i = 0; i < *BFOptionSize; ++i )
- {
- FstEntry[0] = i;
- LstEntry[0] = i + 1;
- BruteForce( FstEntry, LstEntry, BFOption, BFOptionSize, PWLength );
- }
- }
- /* Timer stoppen */
- time( &EndTime );
- puts( "!!! Wort nicht gefunden !!!" );
- printf( "Elapsed time: %ld minutes %ld secondsnn", ( EndTime - StartTime ) / 60, ( EndTime - StartTime ) % 60 );
- return EXIT_FAILURE;
- }
- static void BruteForce( const int * restrict FirstEntry, const int * restrict LastEntry, const char *Letters, const int *NLetters, int PSSWDLength )
- {
- char Password[PSSWDLength];
- int Entry[PSSWDLength + 1];
- int i, j;
- /* Null-Byte hinzufügen */
- memset( Entry, '