1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| #define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h>
char letter[37] = "abcdefghijklmnopqrstuvwxyz0123456789"; char result[10]; int minlen = 1; int maxlen = 10;
char *encrypted = "$6$jMzjGK/$0QVw8FM87jd3yF0wvzgXPPe1l3FOfrIA7LhGPIVCbum9es5 /tQsGMJqmaQ78IY.Hv4h6UWnvTs4cLntrPMSfM/"; char *salt = "$6$jMzjGK//$";
void try_next(int index, int length) { int i; if(index == length) return ; for(i = 0; i< 36; i++) { result[index] = letter[i]; memset(result + index +1, letter[0], length – index -1); if(i != 0) { printf("尝试:%s\n", result); if(! strcmp(encrypted, crypt(result, salt))) { printf("发现密码:%s\n", result); exit (0); } } try_next(index + 1, length); } }
void try(int length, int begin, int end) { int i; for(i = begin; i<= end; i++) { result[0] = letter[i]; memset(result + 1, letter[0], length-1); printf("尝试:%s\n", result); if(!strcmp(encrypted, crypt(result, salt))) { printf("发现密码:%s\n", result); exit (0); } try_next(1, length); } }
int main() { int len; for(len = minlen; len <= maxlen; len++){ printf("\n正在尝试长度为%d的密码\n", len); memset(result, 0, 10); try(len, 0, 36); } return 0; }
|