Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <stdbool.h>
- #include <inttypes.h>
- #include <string.h>
- #include <openssl/sha.h>
- char *bin2hex(const unsigned char *p, size_t len)
- {
- char *s = malloc((len * 2) + 1);
- unsigned int i;
- if (!s)
- return NULL;
- for (i = 0; i < len; i++)
- sprintf(s + (i * 2), "%02x", (unsigned int) p[i]);
- return s;
- }
- static inline uint32_t swab32(uint32_t v)
- {
- return bswap_32(v);
- }
- void pack32(uint8_t *dest, uint32_t val)
- {
- dest[0] = (val & 0xff000000) >> 24;
- dest[1] = (val & 0x00ff0000) >> 16;
- dest[2] = (val & 0x0000ff00) >> 8;
- dest[3] = (val & 0x000000ff) ;
- }
- int main(int argc, char *argv[])
- {
- unsigned char hash1[32];
- unsigned char hash2[32];
- unsigned char coinbase[200];
- memset(coinbase, sizeof(coinbase), 0);
- const char *text = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";
- pack32(coinbase, 486604799); //nBits in decimal form
- pack32(coinbase+4, 66629);// This is represented as CBigNum(4) in the code
- memcpy(coinbase+8, (const unsigned char *)text, strlen(text));
- char *d = bin2hex(coinbase, strlen(text)+8);
- printf("%s\n", d);
- free(d);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement