SHARE
TWEET

Untitled

a guest Apr 14th, 2013 144 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include <stdbool.h>
  5. #include <inttypes.h>
  6. #include <string.h>
  7. #include <openssl/sha.h>
  8.  
  9. char *bin2hex(const unsigned char *p, size_t len)
  10. {
  11.         char *s = malloc((len * 2) + 1);
  12.         unsigned int i;
  13.  
  14.         if (!s)
  15.                 return NULL;
  16.  
  17.         for (i = 0; i < len; i++)
  18.                 sprintf(s + (i * 2), "%02x", (unsigned int) p[i]);
  19.  
  20.         return s;
  21. }
  22.  
  23.        
  24. static inline uint32_t swab32(uint32_t v)
  25. {
  26.         return bswap_32(v);
  27. }      
  28.  
  29. void pack32(uint8_t *dest, uint32_t val)
  30. {
  31.         dest[0] = (val & 0xff000000) >> 24;
  32.         dest[1] = (val & 0x00ff0000) >> 16;
  33.         dest[2] = (val & 0x0000ff00) >>  8;
  34.         dest[3] = (val & 0x000000ff)      ;
  35. }
  36.  
  37. int main(int argc, char *argv[])
  38. {
  39.         unsigned char hash1[32];
  40.         unsigned char hash2[32];
  41.         unsigned char coinbase[200];
  42.         memset(coinbase, sizeof(coinbase), 0);
  43.         const char *text = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";
  44.         pack32(coinbase, 486604799); //nBits in decimal form
  45.         pack32(coinbase+4, 66629);// This is represented as CBigNum(4) in the code
  46.         memcpy(coinbase+8, (const unsigned char *)text, strlen(text));
  47.  
  48.         char *d = bin2hex(coinbase, strlen(text)+8);
  49.         printf("%s\n", d);
  50.         free(d);
  51.        
  52.         return 0;
  53. }
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