Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <assert.h>
- #include <string.h>
- #include <regex.h>
- #include <crypt.h> // -lcrypt
- #include <pthread.h> // -lpthread
- const char* chars = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
- size_t chars_len;
- void* thread(void* arg) {
- char pass[15], salt[3], trip[11];
- size_t pass_len;
- salt[2] = 0;
- trip[10] = 0;
- int i;
- while(1) {
- pass_len = 5 + rand() % 8; // 5..10
- for(i = 0; i < pass_len; i++)
- pass[i] = chars[rand() % chars_len];
- pass[pass_len] = 0;
- strncpy(salt, &pass[1], 2);
- strncpy(trip, &(crypt(pass, salt))[3], 10);
- if(regexec((regex_t*)arg, trip, 0, NULL, 0) == 0)
- printf("!%s=%s\n", trip, pass);
- }
- }
- int main(int argc, char* argv[]) {
- if(argc < 2 || argc > 3) {
- printf("Usage: %s [regex] {threads}\n", argv[0]);
- return 0;
- }
- char* find = argv[1];
- chars_len = strlen(chars);
- srand(time(NULL));
- regex_t regex;
- assert(regcomp(®ex, find, REG_EXTENDED | REG_ICASE) == 0);
- if(argc > 2) {
- int num_threads = atoi(argv[2]);
- assert(num_threads > 0 && num_threads <= 20);
- pthread_t threads[num_threads];
- int i;
- for(i = 0; i < num_threads; i++)
- pthread_create(&threads[i], NULL, thread, (void*)®ex);
- for(i = 0; i < num_threads; i++)
- pthread_detach(threads[i]);
- }
- thread((void*)®ex);
- regfree(®ex);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement