Advertisement
Guest User

Untitled

a guest
Jan 25th, 2013
1,168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <string.h>
  4. #include <openssl/md5.h>
  5.  
  6. // compile: gcc -o subhash subhash.c -lcrypto -O2 -Wall
  7. // by atom
  8.  
  9. int main(int argc, char *argv[])
  10. {
  11.   if (argc != 2)
  12.   {
  13.     fprintf (stderr, "Usage: %s hash\n", argv[0]);
  14.  
  15.     return -1;
  16.   }
  17.  
  18.   uint32_t target;
  19.  
  20.   if (sscanf (argv[1], "%08x", &target) != 1)
  21.   {
  22.     fprintf (stderr, "Something is wrong with your hash: %s", argv[1]);
  23.  
  24.     return -1;
  25.   }
  26.  
  27.   target = __builtin_bswap32 (target);
  28.  
  29.   char buf[BUFSIZ];
  30.  
  31.   while (fgets (buf, BUFSIZ, stdin))
  32.   {
  33.     uint32_t digest[4];
  34.  
  35.     MD5_CTX c;
  36.  
  37.     MD5_Init (&c);
  38.  
  39.     MD5_Update (&c, buf, strlen (buf) - 1);
  40.  
  41.     MD5_Final ((unsigned char *) digest, &c);
  42.  
  43.     if (target != digest[0]) continue;
  44.  
  45.     printf ("Password matches: %s", buf);
  46.  
  47.     break;
  48.   }
  49.  
  50.   return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement