SHARE
TWEET

Looks for string with lowest sha512 hash

rainman002 Feb 16th, 2014 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <stdint.h>
  4. #include <string.h>
  5. #include <pthread.h>
  6. #include <openssl/sha.h>
  7.  
  8. typedef struct {
  9.     int threadid;
  10.     int iterations;
  11.     uint64_t dataMin;
  12.     unsigned char outputMin[64];
  13. } Setup;
  14.  
  15. void* runSearch(void* context)
  16. {
  17.     Setup* setup = context;
  18.     uint64_t data = setup->threadid;
  19.     unsigned char output[64];
  20.     setup->dataMin = data;
  21.     unsigned char* min = setup->outputMin;
  22.     min[0] = 0xff;
  23.    
  24.     data &= 0x1f1f1f1f1f1f1f1fll;
  25.     data |= 0x4040404040404040ll;
  26.     for(int x=0 ; x<setup->iterations ; x++)
  27.     {
  28.         SHA512((unsigned char*)&data, 8, output);
  29.         for(int i=0 ; i<64 ; i++)
  30.         {
  31.             if(output[i] < min[i])
  32.             {
  33.                 memcpy(min, output, 64);
  34.                 setup->dataMin = data;
  35.                 break;
  36.             }
  37.             else if(output[i] > min[i])
  38.             {
  39.                 break;
  40.             }
  41.         }
  42.         data |= 0xe0e0e0e0e0e0e0e0ll;
  43.         data += 8;
  44.         data &= 0x1f1f1f1f1f1f1f1fll;
  45.         data |= 0x4040404040404040ll;
  46.     }
  47.    
  48.     return NULL;
  49. }
  50.  
  51. Setup setups[8];
  52.  
  53. int main(int argc, char** argv)
  54. {
  55.     int iter = 1000000;
  56.     int threadCount = 1;
  57.     pthread_t threads[8];
  58.     uint64_t dataMin;
  59.     unsigned char outputMin[64] = {0xff};
  60.    
  61.     if(argc > 1) iter = atoi(argv[1]);
  62.     if(argc > 2) threadCount = atoi(argv[2]);
  63.    
  64.     for(int i=0 ; i<threadCount ; i++)
  65.     {
  66.         setups[i] = (Setup){.threadid=i, .iterations=iter};
  67.         pthread_create(&threads[i], NULL, runSearch, &setups[i]);
  68.     }
  69.    
  70.     for(int i=0 ; i<threadCount ; i++)
  71.     {
  72.         pthread_join(threads[i], NULL);
  73.     }
  74.    
  75.    
  76.     for(int t=0 ; t<threadCount ; t++)
  77.     {
  78.         unsigned char* min = setups[t].outputMin;
  79.         for(int i=0 ; i<64 ; i++)
  80.         {
  81.             if(min[i] < outputMin[i])
  82.             {
  83.                 memcpy(&outputMin, min, 64);
  84.                 dataMin = setups[t].dataMin;
  85.                 break;
  86.             }
  87.             else if(min[i] > outputMin[i])
  88.             {
  89.                 break;
  90.             }
  91.         }
  92.     }
  93.    
  94.     for(int i=0 ; i<8 ; i++)
  95.         printf("%c", ((char*)&dataMin)[i]);
  96.     puts("");
  97.    
  98.     for(int i=0 ; i<64 ; i++)
  99.         printf("%.2x", outputMin[i]);
  100.     puts("");
  101. }
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