Advertisement
theanonym

tripcode.c

May 21st, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.48 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <assert.h>
  4. #include <string.h>
  5. #include <regex.h>
  6. #include <crypt.h>   // -lcrypt
  7. #include <pthread.h> // -lpthread
  8.  
  9. const char* chars = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  10. size_t chars_len;
  11.  
  12. void* thread(void* arg) {
  13.    char pass[15], salt[3], trip[11];
  14.    size_t pass_len;
  15.    salt[2]  = 0;
  16.    trip[10] = 0;
  17.    int i;
  18.    while(1) {
  19.       pass_len = 5 + rand() % 8; // 5..10
  20.       for(i = 0; i < pass_len; i++)
  21.          pass[i] = chars[rand() % chars_len];
  22.       pass[pass_len] = 0;
  23.       strncpy(salt, &pass[1], 2);
  24.       strncpy(trip, &(crypt(pass, salt))[3], 10);
  25.       if(regexec((regex_t*)arg, trip, 0, NULL, 0) == 0)
  26.          printf("!%s=%s\n", trip, pass);
  27.    }
  28. }
  29.  
  30. int main(int argc, char* argv[]) {
  31.    if(argc < 2 || argc > 3) {
  32.       printf("Usage: %s [regex] {threads}\n", argv[0]);
  33.       return 0;
  34.    }
  35.    char* find = argv[1];
  36.    chars_len = strlen(chars);
  37.    srand(time(NULL));
  38.    regex_t regex;
  39.    assert(regcomp(&regex, find, REG_EXTENDED | REG_ICASE) == 0);
  40.    if(argc > 2) {
  41.       int num_threads = atoi(argv[2]);
  42.       assert(num_threads > 0 && num_threads <= 20);
  43.       pthread_t threads[num_threads];
  44.       int i;
  45.       for(i = 0; i < num_threads; i++)
  46.          pthread_create(&threads[i], NULL, thread, (void*)&regex);
  47.       for(i = 0; i < num_threads; i++)
  48.          pthread_detach(threads[i]);
  49.    }
  50.    thread((void*)&regex);
  51.    regfree(&regex);
  52.    return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement