Skip to content

Instantly share code, notes, and snippets.

@toinetoine
Last active March 19, 2017 08:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toinetoine/61d0de8d2367b7824a37539105feaced to your computer and use it in GitHub Desktop.
Save toinetoine/61d0de8d2367b7824a37539105feaced to your computer and use it in GitHub Desktop.
#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <openssl/sha.h>
#include <unistd.h> // for sleep
using namespace std;
vector<char> hexToBytes(const string& hex) {
vector<char> bytes;
for (unsigned int i = 0; i < hex.length(); i += 2) {
string byteString = hex.substr(i, 2);
char byte = (char) strtol(byteString.c_str(), NULL, 16);
bytes.push_back(byte);
}
return bytes;
}
string sha256(const string str)
{
// unsigned int SHA256_DIGEST_LENGTH = 256;
unsigned char hash[SHA256_DIGEST_LENGTH];
SHA256_CTX sha256;
SHA256_Init(&sha256);
SHA256_Update(&sha256, str.c_str(), str.size());
SHA256_Final(hash, &sha256);
stringstream ss;
for(int i = 0; i < SHA256_DIGEST_LENGTH; i++)
{
ss << hex << setw(2) << setfill('0') << (int)hash[i];
}
return ss.str();
}
string sha256(const vector<char> inputBuf)
{
// unsigned int SHA256_DIGEST_LENGTH = 256;
unsigned char hash[SHA256_DIGEST_LENGTH];
SHA256_CTX sha256;
SHA256_Init(&sha256);
SHA256_Update(&sha256, inputBuf.data(), inputBuf.size());
SHA256_Final(hash, &sha256);
stringstream ss;
for(int i = 0; i < SHA256_DIGEST_LENGTH; i++)
{
ss << hex << setw(2) << setfill('0') << (int)hash[i];
}
return ss.str();
}
int main() {
string input = "0100000081cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122bc7f5d74df2b9441a42a14695";
while(true) {
cout << sha256(hexToBytes(input)) << endl;
cout << sha256(hexToBytes(sha256(hexToBytes(input)))) << endl;
usleep(1000000);
}
return 0;
}
@toinetoine
Copy link
Author

todo: split out nonce, date, etc. and have iterating logic

@toinetoine
Copy link
Author

Notes

  • need sudo apt-get install libssl-dev for openssl/sha.h

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment