SHARE
TWEET

Untitled

a guest Sep 22nd, 2016 802 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <time.h>
  5. #include <openssl/sha.h>
  6.  
  7. const char *coin_err;
  8. #define bail(s) { coin_err = s; return 0; }
  9.  
  10. int unbase58(const char *s, unsigned char *out) {
  11.     static const char *tmpl = "123456789"
  12.         "ABCDEFGHJKLMNPQRSTUVWXYZ"
  13.         "abcdefghijkmnopqrstuvwxyz";
  14.     int i, j, c;
  15.     const char *p;
  16.  
  17.     memset(out, 0, 40);
  18.     for (i = 0; s[i]; i++) {
  19.         if (!(p = strchr(tmpl, s[i])))
  20.             bail("bad char");
  21.  
  22.         c = p - tmpl;
  23.         for (j = 37; j--; ) {
  24.             c += 58 * out[j];
  25.             out[j] = c % 256;
  26.             c /= 256;
  27.         }
  28.  
  29.         if (c) bail("address too long");
  30.     }
  31.  
  32.     return 1;
  33. }
  34.  
  35. int valid(const char *s) {
  36.     unsigned char dec[40], d1[SHA256_DIGEST_LENGTH], d2[SHA256_DIGEST_LENGTH];
  37.  
  38.     coin_err = "";
  39.     if (!unbase58(s, dec)) return 0;
  40.  
  41.     SHA256(SHA256(dec, 33, d1), SHA256_DIGEST_LENGTH, d2);
  42.  
  43.     if (memcmp(dec + 33, d2, 4))
  44.         bail("bad digest");
  45.  
  46.     return 1;
  47. }
  48.  
  49. #define C_1_INDEX 6
  50. #define C_2_INDEX 11
  51. #define C_3_INDEX 27
  52. #define C_4_INDEX 34
  53. #define C_5_INDEX 47
  54.  
  55. int main (void) {
  56.     const char *chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
  57.     char addr[100];
  58.     strcpy(addr, "5HpHag-65TZ-G1PH3CSu63k8Dbp-D8s5ip-nEB3kEsreAnc-uDf");
  59.  
  60.     int i;
  61.     for (i = 0; addr[i]; i++) {
  62.         if (addr[i] == '-') printf("index: %d\n", i);
  63.     }
  64.  
  65.     int c1 = 0, c2 = 0, c3 = 0, c4 = 0, c5 = 0, status;
  66.     float startTime, endTime;
  67.     for (c1 = 0; c1 < 58; c1++) {
  68.         addr[C_1_INDEX] = chars[c1];
  69.         for (c2 = 0; c2 < 58; c2++) {
  70.             addr[C_2_INDEX] = chars[c2];
  71.             printf("Test: %c%c...", chars[c1], chars[c2]);fflush(stdout);
  72.             startTime = (float)clock()/CLOCKS_PER_SEC;
  73.             for (c3 = 0; c3 < 58; c3++) {
  74.                 addr[C_3_INDEX] = chars[c3];
  75.                 for (c4 = 0; c4 < 58; c4++) {
  76.                     addr[C_4_INDEX] = chars[c4];
  77.                     for (c5 = 0; c5 < 58; c5++) {
  78.                         addr[C_5_INDEX] = chars[c5];
  79.                         status = valid(addr);
  80.                         if (status) {
  81.                             printf("\nFOUND: %s\n", addr);
  82.                             return 1;
  83.                         }
  84.                     }
  85.                 }
  86.             }
  87.             endTime = (float)clock()/CLOCKS_PER_SEC;
  88.             printf("%fs\n", (endTime-startTime));
  89.         }
  90.     }
  91.  
  92.     return 0;
  93. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top