程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> Openmp在暴力猜測MD5源字串一例

Openmp在暴力猜測MD5源字串一例

編輯:C++入門知識

//gcc -fopenmp -O2 -static -s omp_pwd_md5.c md5.c -o omp_pwd_md5.exe 
#include <stdio.h> 
#include "md5.h" 
#include <omp.h> 
 
#define PASSWD_MAXLEN 32 
#define PASSWD_SET_SIZE 36 
const char *passwd_words = "0123456789abcdefghijklmnopqrstuvwxyz_-.,"; 
const char *real_pass_digest = "\x5d\x41\x40\x2a\xbc\x4b\x2a\x76\xb9\x71\x9d\x91\x10\x17\xc5\x92"; 
int compare_pass(int passwd_len , char *passwd) 

    int i; 
    int match = 0; 
    unsigned int *p1, *p2; 
    p2 = (unsigned int *)real_pass_digest; 
    //printf("Guess Password: %s", passwd); 
    md5_state_t ms; 
    md5_byte_t digest[16]; 
    md5_init(&ms); 
    md5_append(&ms, passwd, passwd_len); 
    md5_finish(&ms, digest); 
    p1 = (unsigned int *)digest; 
    for(i = 0; i < 4; i++) 
    { 
        if(p1[i] == p2[i]) match++; 
    } 
    i = 0; 
    if(match == 4) 
    { 
        i = 1; 
        printf("String: %s -- Matched!", passwd); 
    } 
    return i; 

 
void passwd_gen() 

    int core_nums = omp_get_num_procs(); 
    printf("Core Number:%d\n", core_nums); 
    int i, finded = 0; 
    int len = 0, passwd_count = 0; 
    int PP[PASSWD_MAXLEN]; 
    int *passlen = (int *)malloc(sizeof(int)*core_nums); 
    char *passwd = (char *)malloc(PASSWD_MAXLEN * core_nums); 
    for(i = 0; i < PASSWD_MAXLEN; i++) 
    { 
        PP[i] = 0; 
        passwd[i] = 0; 
    } 
    int pos = 0; 
    while(1) 
    { 
        PP[pos]++; 
        if(PP[pos] == PASSWD_SET_SIZE) 
        { 
            PP[pos] = 0;pos++; 
            continue; 
        } 
        else 
        { 
            len = pos > len ? pos : len ; 
            pos = 0; 
            for(i = 0; i < len + 1; i++) passwd[PASSWD_MAXLEN*passwd_count + i] = passwd_words[ PP[i] ]; 
            passlen[passwd_count] = len + 1; 
            passwd_count++; 
            if(passwd_count == core_nums) 
            { 
                passwd_count = 0; 
                #pragma omp parallel for 
                for(i = 0; i < core_nums; i++) 
                { 
                    finded += compare_pass(passlen[i], passwd + PASSWD_MAXLEN*i); 
                } 
                if(finded) break; 
            } 
        } 
    } 
    free(passwd); 
    free(passlen); 

 
int main( int argc, char *argv[] ) 

    passwd_gen(); 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved